Hi R-users, I have a set of data from 1958-2009, how do I extract the data from 1927 and 2007? ? beechworth.dt ???? Year Month? Rain 1??? 1858???? 3? 21.8 2??? 1858???? 4? 47.0 3??? 1858???? 5? 70.1 4??? 1858???? 6? 78.7 5??? 1858???? 7 101.6 6??? 1858???? 8 129.8 7??? 1858???? 9? 80.8 8??? 1858??? 10? 41.9 ?... ? ???? 2009??? ...... ? ? I tried: ? ?beechworth.dt.2 <- beechworth.dt[beechworth.dt$Year=="1927":"2007",] ? and got ? Warning message: In beechworth.dt$Year == "1927":"2007" : ? longer object length is not a multiple of shorter object length ? Thank you so much for any help given.
Hi, maybe the following line works for you: beechworth.dt.2 <- beechworth.dt[as.numeric(beechworth.dt$Year) %in% 1927:2007, ] (using as.numeric() to make sure that "Year" is numeric, maybe not needed?). Christian
On Sun, 19 Apr 2009 23:59:43 -0700 (PDT) Roslina Zakaria <zroslina at yahoo.com> wrote: RZ> I have a set of data from 1958-2009, how do I extract the data from RZ> 1927 and 2007? RZ> beechworth.dt RZ> ???? Year Month? Rain how about: beech.cut<-subset(beechworth.dt,(Year>1926&Year<2008)) hth Stefan
Roslina Zakaria wrote:> Hi R-users, > > I have a set of data from 1958-2009, how do I extract the data from 1927 and 2007? > > beechworth.dt > Year Month Rain > 1 1858 3 21.8 > 2 1858 4 47.0 > 3 1858 5 70.1 > 4 1858 6 78.7 > 5 1858 7 101.6 > 6 1858 8 129.8 > 7 1858 9 80.8 > 8 1858 10 41.9 > ... > > 2009 ...... > > > I tried: > > beechworth.dt.2 <- beechworth.dt[beechworth.dt$Year=="1927":"2007",]You probably want to index with beechworth.dt$Year %in% 1927:2007 or beechworth.dt$Year %in% c(1927, 2007) (not sure which one given your question "from 1927 and 2007"). Uwe Ligges> > and got > > Warning message: > In beechworth.dt$Year == "1927":"2007" : > longer object length is not a multiple of shorter object length > > Thank you so much for any help given. > > > > > ______________________________________________ > 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.
If Year is numeric data, then you can use: beechworth.dt.2 <- subset(beechworth.dt, Year>=1997 & Year <=2008) If it is character, then you can use: beechworth.dt.2 <- subset(beechworth.dt, Year %in% as.character(1997:2008)) 2009/4/20 Roslina Zakaria <zroslina at yahoo.com>:> > Hi R-users, > > I have a set of data from 1958-2009, how do I extract the data from 1927 and 2007? > > beechworth.dt > ???? Year Month? Rain > 1??? 1858???? 3? 21.8 > 2??? 1858???? 4? 47.0 > 3??? 1858???? 5? 70.1 > 4??? 1858???? 6? 78.7 > 5??? 1858???? 7 101.6 > 6??? 1858???? 8 129.8 > 7??? 1858???? 9? 80.8 > 8??? 1858??? 10? 41.9 > ?... > > ???? 2009??? ...... > > > I tried: > > ?beechworth.dt.2 <- beechworth.dt[beechworth.dt$Year=="1927":"2007",] > > and got > > Warning message: > In beechworth.dt$Year == "1927":"2007" : > ? longer object length is not a multiple of shorter object length > > Thank you so much for any help given. > > > > > ______________________________________________ > 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. >-- HUANG Ronggui, Wincent PhD Candidate Dept of Public and Social Administration City University of Hong Kong Home page: http://asrr.r-forge.r-project.org/rghuang.html
Hi, Try this one: beechworth.dt.2 <- beechworth.dt[beechworth.dt$Year>="1927" & beechworth.dt$Year<="2007",] Martins On Apr 20, 9:59?am, Roslina Zakaria <zrosl... at yahoo.com> wrote:> Hi R-users, > > I have a set of data from 1958-2009, how do I extract the data from 1927 and 2007? > ? > beechworth.dt > ???? Year Month? Rain > 1??? 1858???? 3? 21.8 > 2??? 1858???? 4? 47.0 > 3??? 1858???? 5? 70.1 > 4??? 1858???? 6? 78.7 > 5??? 1858???? 7 101.6 > 6??? 1858???? 8 129.8 > 7??? 1858???? 9? 80.8 > 8??? 1858??? 10? 41.9 > ?... > ? > ???? 2009??? ...... > ? > ? > I tried: > ? > ?beechworth.dt.2 <- beechworth.dt[beechworth.dt$Year=="1927":"2007",] > ? > and got > ? > Warning message: > In beechworth.dt$Year == "1927":"2007" : > ? longer object length is not a multiple of shorter object length > ? > Thank you so much for any help given. > > ______________________________________________ > R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.