subset exact values
On Thu, 22 Jan 2009, tsippel wrote:
Hi- I need to subset the following data by the column 'dal' for values that equal the regular interval seq(0, 150, by=0.5) exactly.... ....excluding rows with irregular 'dal' values such as c(2.888958, 2.891620), etc. data<-data.frame(id=id, dal=dal, date=date, mu.x=mu.x) $dal [1] 0.000000 0.500000 1.000000 1.500000 2.000000 2.500000 2.888958 2.891620 3.000000 3.245405 3.500000 3.688333 4.000000 4.500000 4.738831 4.855949 [17] 4.993437 5.000000 5.251875 5.252037 5.500000 $id [1] STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 STM05.3 [19] STM05.3 STM05.3 STM08.2 $date [1] "2005-02-26 00:00:00" "2005-02-26 12:00:00" "2005-02-27 00:00:00" "2005-02-27 12:00:00" "2005-02-28 00:00:00" "2005-02-28 12:00:00" [7] "2005-02-28 21:20:06" "2005-02-28 21:23:56" "2005-03-01 00:00:00" "2005-03-01 05:53:23" "2005-03-01 12:00:00" "2005-03-01 16:31:12" [13] "2005-03-02 00:00:00" "2005-03-02 12:00:00" "2005-03-02 17:43:55" "2005-03-02 20:32:34" "2005-03-02 23:50:33" "2005-03-03 00:00:00" [19] "2005-03-03 06:02:42" "2005-03-03 06:02:56" "2005-03-03 12:00:00" $mu.x [1] 176.2730 176.3550 176.4996 176.6969 176.9209 177.1511 177.3197 177.3197 177.3109 177.2958 177.5862 177.7929 177.7612 177.6563 177.6030 177.6421 [17] 177.6932 177.6949 177.7377 177.7377 177.7468 Why does the following subset code give me rows of data with irregular 'dal' values which do not exactly match values in 'seq' below? seq<-seq(0, 150, 0.5) reg<-subset(data, dal=seq, select=c(id, dal, date, mu.x))
Same reason that this doesn't return only those rows where V2 is 1:
dat <- as.data.frame(diag(2)) subset(dat,V2=1)
V1 V2 1 1 0 2 0 1
which I suspect is a typo or a misunderstanding of what '=' means. Have a look at the manuals. While you are there look at FAQ 7.31 'Why doesn't R think these numbers are equal?' to be sure you don't get tripped up by that issue. HTH, Chuck
Thanks, Tim -- View this message in context: http://www.nabble.com/subset-exact-values-tp21615855p21615855.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901