[R] delete a row from a matrix

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Jul 13 11:38:30 CEST 2005


Navarre Sabine <navarre_sabine at yahoo.fr> writes:

> Hi,
> I would like to know if it's possible to delete a rox from a matrix?
>  
> > fig
>      [,1] [,2] [,3] [,4]
> [1,]    0    1  0.0  0.2
> [2,]    0    1  0.2  0.8
> [3,]    0    1  0.8  1.0
> [4,]    0    1   NA   NA
> [5,]    0    1   NA   NA
> 
> I would like to delete the 2 rows with NA!

fig <- fig[-c(4,5),]

or, more generally

fig <- fig[complete.cases(fig),] 

or, even more generally

fig <- fig[!apply(is.na(fig), 1, any),]

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list