An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110428/c8606a43/attachment.pl>
subset without removing NAs
5 messages · Benjamin Caldwell, Jannis, Marc Schwartz +1 more
On Apr 28, 2011, at 3:21 PM, Jannis wrote:
On 04/28/2011 09:53 PM, Benjamin Caldwell wrote:
rws50<- subset(rw.fire.RW,shigo.av<50)
quick and dirty would be to replace all NAs with -99999 (or similar), use subset, and set all values ==-99999 in the subset back to NA. There may be more elegant solutions, though.
Indeed. See ?is.na DF <- data.frame(A = 1:20, B = c(1:15, rep(NA, 5)))
subset(DF, B > 10)
A B 11 11 11 12 12 12 13 13 13 14 14 14 15 15 15
subset(DF, (B > 10) | is.na(B))
A B 11 11 11 12 12 12 13 13 13 14 14 14 15 15 15 16 16 NA 17 17 NA 18 18 NA 19 19 NA 20 20 NA HTH, Marc Schwartz
On Apr 28, 2011, at 3:53 PM, Benjamin Caldwell wrote:
Hi folks, I'm dealing with a dataset with a lot of NAs, and want to use subset on the data without removing the NAs from the the dataframe; e.g. rws50 <- subset(rw.fire.RW,shigo.av<50) This removes instances with NA for the value in addition to anything <50. Any suggestions much appreciated.
If you use "[" instead the NA's will come though: rw.fire.RW[ shigo.av<50, ] In fact I generally wrap my logicals in which to avoid such (mis?)behavior. but you appear to approve of it. == David Winsemius, MD West Hartford, CT
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110428/9c3237dc/attachment.pl>