Sorry folks but again I have failed in my understanding of how to do a very simple thing. I've read the various texts and searched the help archives but no positive result so far. I want to remove all the rows in a data frame where one of the variables has negative values. In approx Stata pseudocode: drop _all, if( x < 0 ) Please either point me to relevant sections of the docs or supply me with solution - I'm sure it's very simple. Michael
Michael Hopkins <michael.hopkins at hopkins-research.com> writes:> Sorry folks but again I have failed in my understanding of how to do a very > simple thing. I've read the various texts and searched the help archives > but no positive result so far. > > I want to remove all the rows in a data frame where one of the variables has > negative values. In approx Stata pseudocode: > > drop _all, if( x < 0 ) > > Please either point me to relevant sections of the docs or supply me with > solution - I'm sure it's very simple.There are variations: d1 <- subset(d, x < 0) d1 <- d[d$x < 0,] d1 <- d[d$x < 0 & !is.na(d$x),] # essentially same as subset() -- 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
To leave x with only the non-negative elements, you can use x[x >= 0]. Also see the function "subset". Hope this helps, Matt Wiener -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Michael Hopkins Sent: Friday, July 15, 2005 8:00 AM To: r-help at stat.math.ethz.ch Subject: [R] Another simple q - removing negative values Sorry folks but again I have failed in my understanding of how to do a very simple thing. I've read the various texts and searched the help archives but no positive result so far. I want to remove all the rows in a data frame where one of the variables has negative values. In approx Stata pseudocode: drop _all, if( x < 0 ) Please either point me to relevant sections of the docs or supply me with solution - I'm sure it's very simple. Michael ______________________________________________ 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