[R] to extract particular date/data
Richard.Cotton at hsl.gov.uk
Richard.Cotton at hsl.gov.uk
Fri May 2 13:15:51 CEST 2008
> 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:
> rainfall
Year 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}}
More information about the R-help
mailing list