[R] data frame subsets?

Douglas M. Hultstrand dmhultst at metstat.com
Fri Nov 13 04:57:01 CET 2009


Hello,

I am trying to create data frame subsets based on binned temperature 
data.  I have code working to create the bins (d.1 and d.2), but it 
takes two steps, I was wondering if I could merge into one step.  See Below

d
    n year mo da hr   t   td  tw rh   kPa
1   1 1945  3  1  0 1.1  0.0 0.6 92 101.7
2   2 1945  3  1  1 2.8 -1.1 1.1 76 101.8
3   3 1945  3  1  2 2.2 -1.7 0.6 75 101.9
4   4 1945  3  1  3 1.7 -1.1 0.6 82 102.0
5   5 1945  3  1  4 1.7 -2.8 0.0 72 102.1
6   6 1945  3  1  5 1.7 -1.7 0.0 78 102.2
7   7 1945  3  1  6 1.1 -2.8 0.0 75 102.2
8   8 1945  3  1  7 1.1 -1.7 0.0 82 102.4
9   9 1945  3  1  8 1.7 -1.1 0.6 82 102.5
10 10 1945  3  1  9 2.8 -3.3 0.6 64 102.6

d.1 <- d[d$t >= 1.0,]
d.2 <- d.1[d.1$t < 2.0,]

How can I make  d.1 and d.2 into one step? I have tried several 
different methods such as example below.
d.1 <- d[d$t >= 1.0, && d$t < 2.0,]

Thanks,
Doug

-- 
---------------------------------
Douglas M. Hultstrand, MS
Senior Hydrometeorologist
Metstat, Inc. Windsor, Colorado
voice: 970.686.1253
email: dmhultst at metstat.com
web: http://www.metstat.com




More information about the R-help mailing list