[R] subset
Rogerio Rosa da Silva
rrsilva at ib.usp.br
Wed Feb 9 14:52:26 CET 2005
Dear all,
I am trying to extract rows from a data.frame based on the
rowSums != 0. I want to preserve rownames in the first column in the subset.
Does anyone know how to extract all species that don't have rowSums equal
to zero? Here it is:
# dataset
x <- data.frame(
species=c("sp.1","sp.2","sp.3","sp.4"),
site1=c(2,3,0,0),
site2=c(0,0,0,0),
site3=c(0,1,0,6),
site4=c(0,0,0,0))
#I want extract the matrix:
species site1 site2 site3 site4
sp.1 2 0 0 0
sp.2 3 0 1 0
sp.4 0 0 6 0
#extract data.frame of rowSums with x[,2:4] != 0
subset (x, apply (x,1,function(row) all(rowSums(x[,2:4] !=0)) ## don't work
Thanks in advance.
--
Rogério R. Silva
MZUSP http://www.mz.usp.br
Linux/Debian User # 354364
Linux counter http://counter.li.org
More information about the R-help
mailing list