Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "rows" with a NA value? [duplicate]

Tags:

r

Possible Duplicate:
R - remove rows with NAs in data.frame

How can I quickly remove "rows" in a dataframe with a NA value in one of the columns?

So

     x1  x2 [1,]  1 100 [2,]  2  NA [3,]  3 300 [4,] NA 400 [5,]  5 500 

should result in:

     x1  x2 [1,]  1 100 [3,]  3 300 [5,]  5 500 
like image 616
waanders Avatar asked May 26 '11 12:05

waanders


People also ask

How do I remove rows containing Na?

To remove all rows having NA, we can use na. omit function. For Example, if we have a data frame called df that contains some NA values then we can remove all rows that contains at least one NA by using the command na. omit(df).

How do I delete rows in Excel with Na value?

Select "Blanks" and click OK. Excel has now selected all of the blank cells in the column. Now carefully right-mouse click on one of the empty cells, and choose Delete from the menu. Then select Entire row, and click the OK button.

How do I delete a row with Na in a specific column?

To drop rows with NA's in some specific columns, you can use the filter() function from the dplyr package and the in.na() function. First, the latter one determines if a value in a column is missing and returns a TRUE or FALSE. Next, the filter function drops all rows with an NA.

Does NA omit remove rows?

na. omit will omit all rows from the calculations.


1 Answers

dat <- data.frame(x1 = c(1,2,3, NA, 5), x2 = c(100, NA, 300, 400, 500))  na.omit(dat)   x1  x2 1  1 100 3  3 300 5  5 500 
like image 56
Chase Avatar answered Sep 21 '22 05:09

Chase