Hi R-expert, If I have this daily rainfall data, how do call a particular day? Year,Month,Day,Amount 1900,12,22,1.3 1900,12,23,0 1900,12,24,0 1900,12,25,0 1900,12,26,0 1900,12,27,0 1900,12,28,0 1900,12,29,4.8 1900,12,30,0.3 1900,12,31,0.5 1901,1,1,0 1901,1,2,3 1901,1,3,0 1901,1,4,0.5 1901,1,5,0 1901,1,6,0 ... I used to use julian.date in S-Plus. Thank you so much for your kind attention and help. ____________________________________________________________________________________ [[elided Yahoo spam]]
I'm trying to drop all rows except for the ones with the most recent year. So I split the data frame by NPERMNO and keep just the last record of all groups. datg=t(sapply(split(datgic, datgic$NPERMNO, drop=TRUE), function(x){return( x[nrow(x),] )})) I get something like this... GVKEY NPERMNO GIC year 10001 12994 10001 55102010 2007 10002 19049 10002 40101015 2007 10009 16739 10009 40101010 1999 Has this been made into a proper data frame. How come the row numbers are not 1,2,3,4...? Thank you so much, and I would really appreciate any help! Mike
What you are seeing are the row numbers of the original locations. If datgic is really a data frame, this is probably what you want using lapply and do.call:> x <- data.frame(a=letters, b=sample(1:4, 26, TRUE)) > y <- lapply(split(x, x$b), tail, 1) > do.call(rbind, y)a b 1 z 1 2 y 2 3 w 3 4 x 4 On Fri, May 2, 2008 at 4:40 AM, Mike H. Ryu <hokyung.ryu at yale.edu> wrote:> I'm trying to drop all rows except for the ones with the most recent year. > So I split the data frame by NPERMNO and keep just the last record of all > groups. > > datg=t(sapply(split(datgic, datgic$NPERMNO, drop=TRUE), function(x){return( > x[nrow(x),] )})) > > > I get something like this... > > GVKEY NPERMNO GIC year > 10001 12994 10001 55102010 2007 > 10002 19049 10002 40101015 2007 > 10009 16739 10009 40101010 1999 > > Has this been made into a proper data frame. How come the row numbers are > not 1,2,3,4...? > > Thank you so much, and I would really appreciate any help! > > Mike > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
> If I have this daily rainfall data, how do call a particular day? > Year,Month,Day,Amount > 1900,12,22,1.3 > 1900,12,23,0 > 1900,12,24,0 > 1900,12,25,0 > 1900,12,26,0 > 1900,12,27,0 > 1900,12,28,0 > 1900,12,29,4.8 > 1900,12,30,0.3 > 1900,12,31,0.5 > 1901,1,1,0 > 1901,1,2,3 > 1901,1,3,0 > 1901,1,4,0.5 > 1901,1,5,0 > 1901,1,6,0 > ... > I used to use julian.date in S-Plus.I read your data in as the following data frame:> rainfallYear Month Day Amount 1 1900 12 22 1.3 2 1900 12 23 0.0 3 1900 12 24 0.0 4 1900 12 25 0.0 5 1900 12 26 0.0 6 1900 12 27 0.0 7 1900 12 28 0.0 8 1900 12 29 4.8 9 1900 12 30 0.3 10 1900 12 31 0.5 11 1901 1 1 0.0 12 1901 1 2 3.0 13 1901 1 3 0.0 14 1901 1 4 0.5 15 1901 1 5 0.0 16 1901 1 6 0.0 You can access only the days with rainfall$Day, but you might also like to convert all the dates to POSIX format. This code will do the trick: posixdates <- with(rainfall, ISOdate(Year, Month, Day)) posixdates is a vector of class POSIXct, which means it is the number of seconds since the start of 1970, with some methods to make it print nicely and behave itself in time series plots. See also ?julian, and the chron package. Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}
Have a look at the zoo package which has three vignettes and R News 4/1. On Fri, May 2, 2008 at 12:27 AM, Roslina Zakaria <zroslina at yahoo.com> wrote:> Hi R-expert, > If I have this daily rainfall data, how do call a particular day? > Year,Month,Day,Amount > 1900,12,22,1.3 > 1900,12,23,0 > 1900,12,24,0 > 1900,12,25,0 > 1900,12,26,0 > 1900,12,27,0 > 1900,12,28,0 > 1900,12,29,4.8 > 1900,12,30,0.3 > 1900,12,31,0.5 > 1901,1,1,0 > 1901,1,2,3 > 1901,1,3,0 > 1901,1,4,0.5 > 1901,1,5,0 > 1901,1,6,0 > ... > I used to use julian.date in S-Plus. > Thank you so much for your kind attention and help. > > > ____________________________________________________________________________________ > > [[elided Yahoo spam]] > > ______________________________________________ > 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. >