[R] Extract rows with non-zero elements
Frankvb
frankieboytje at hotmail.com
Tue May 4 09:50:28 CEST 2010
Dear all,
In my dataset I have 12 columns and 5824 rows. The second column contains
information about the height of a claim: it might be zero or positive. I
would like to do an analysis on the positive part of this matrix, but I do
need the other colums with this. So if there are like 1000 rows where the
second column is positive, I would like to extract this 1000x13 matrix into
another matrix.
The beginning of my code is:
Cars <- read.csv(filename, header=TRUE, row.names=NULL, sep=";")
attach(Cars)
n <- as.numeric(n)
s <- as.numeric(s)
# et cetera, the other variabeles are declared as numeric or as factors
# I've tried to extract the data the following way:
Cars2 <- Cars[Cars$s!=0]
#However, then I get the error message:
Error in `[.data.frame`(Cars, Cars$s != 0) : undefined columns selected
# If I try
s[s!=0]
# I do get the positive s-values, but how can I get all colums in a matrix?
Does anyone know how this can be done? Your help would be greatly
appreciated.
Regards,
Frank van Berkum
--
View this message in context: http://r.789695.n4.nabble.com/Extract-rows-with-non-zero-elements-tp2125128p2125128.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list