How to remove NA values from a column, and the corresponding values from an adjacent column, in R?

0 votes
I have a large dataframe and several columns are full of NAs.

Basically got a "score and class differ in length" error message in a function that doesn't support na.rm, so I want to create two new vectors from the dataframe to use for the function. One vector without the NAs, and the next vector without the corresponding values from the first.

How would I do this?
Aug 4 in Data Analytics by Marcelo
• 120 points
105 views

1 answer to this question.

0 votes

Hi@Marcelo,

You can use the filter keyword to find NAN values. It will search for all the position which has NAN values. 

$ df %>% filter(!is.na(col1))
answered Aug 4 by MD
• 56,480 points
Thank you for your answer @MD !

Will this filter out the corresponding values from a sector vector as well?

Related Questions In Data Analytics

0 votes
1 answer

How to write a custom function which will replace all the missing values in a vector with the mean of values in R?

Consider this vector: a<-c(1,2,3,NA,4,5,NA,NA) Write the function to impute ...READ MORE

answered Jul 4, 2018 in Data Analytics by CodingByHeart77
• 3,720 points
1,028 views
+1 vote
2 answers
+1 vote
1 answer

Remove NA values from the output in R programming

Edit your code: columnmean <- function(x, removeNA = ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 51,950 points
93 views
0 votes
1 answer

How do I remove an element from a list by index in R?

Use list[index] = NULL The list value will ...READ MORE

answered Oct 31, 2019 in Data Analytics by Cherukuri
• 32,490 points
146 views
0 votes
2 answers

R programming: Removing NA values

Hi, Use na.rm = TRUE or Fetch values which has ...READ MORE

answered Aug 30, 2019 in Data Analytics by anonymous
• 32,490 points
203 views
+1 vote
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 32,490 points
414 views
0 votes
4 answers

How to remove NA values from a Vector in R?

You can try na.omit() or na.exclude() too. ...READ MORE

answered Jul 31, 2019 in Data Analytics by anonymous
• 32,490 points
48,501 views
+10 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 8, 2018 in Data Analytics by Abhi
• 3,680 points
194 views
0 votes
1 answer

How to extract specific columns from a dataframe in R?

Hi@akhtar, You can use the select method to ...READ MORE

answered Aug 7 in Data Analytics by MD
• 56,480 points
80 views
0 votes
1 answer