[R] removing all NA rows from a data.frame

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon May 28 17:42:53 CEST 2007



Taka Matzmoto wrote:
> Dear R-users,
> 
> I have a data.frame having NA (e.g., 2nd, 4th rows, etc).
> 
>      Start End   Length Variable_name
> [1,] "1"   "1"   "1"    "a"
> [2,] NA    NA    NA     ""
> [3,] "2"   "2"   "1"    "b"
> [4,] NA    NA    NA     ""
> [5,] "3"   "6"   "4"    "c"
> [6,] "7"   "10"  "4"    "d"
> :
> :
> :
> 
> I like to remove the rows having NA in the first column ("Start")
> What is the most elegant way to do this? I think I can use for loop to 
> remove.
> I am looking for a better way.


newX <- X[!is.na(X[,1]),]

Uwe Ligges



> Thanks
> 
> Taka,
> 
> _________________________________________________________________
> 
> Hotmail.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list