I have a huge vector which has a couple of NA values, and I'm trying to find the max value in that vector (the vector is all numbers), but I can't do this because of the NA values.
How can I remove the NA values so that I can compute the max?
To remove NA’s from a vector use the following code:
Vec <- Vec[!is.na(Vec)]
Vec <- c(1, 100, NA, 10,NA,5,6,7,8,9,4,3,5,NA)Vec <- Vec[!is.na(Vec)]Vec  1 100 10 5 6 7 8 9 4 3 5
Vec <- c(1, 100, NA, 10,NA,5,6,7,8,9,4,3,5,NA)
 1 100 10 5 6 7 8 9 4 3 5
You can also use the na.rm argument inside the max function to find the maximum number.
Vec <- c(1, 100, NA, 10,NA,5,6,7,8,9,4,3,5,NA)max(Vec, na.rm = TRUE)Output: 100
max(Vec, na.rm = TRUE)
If you want to explore more in R programming then watch this R programming tutorial for beginner:
I think you can use na.omit function. A lot of the regression routines use it internally:
vec <- 1:1000vec[runif(200, 1, 1000)] <- NAmax(vec)# NAmax( na.omit(vec) )# 1000
vec <- 1:1000
vec[runif(200, 1, 1000)] <- NA
max( na.omit(vec) )
Certification in Digital Marketing |
Certification in Big Data Analytics |
Certification in Cloud & Devops |
Certification in Full Stack Web Development
Big Data and Data Science Master’s Course |
Data Science Architect Master’s Program |
Cloud and DevOps Architect Master’s Course |
Artificial Intelligence Engineer Master’s Course |
Microsoft Azure Certification Master’s Training
Data Science Course Online |
Big Data Hadoop Certification Training |
Machine Learning Course Online |
Artificial Intelligence Course and Training |
Salesforce Certification Training: Administrator and App Builder |
Tableau Training and Certification Course |
Python Data Science Course & Training |
Ethical Hacking Course |
Business Analyst Course |
Courses in Cyber Security
© COPYRIGHT 2011-2021 INTELLIPAAT.COM. ALL RIGHTS RESERVED.
Download Salary Trends Now !
Learn how professionals like you got up to 100% Salary Hike.