Re: [R] to extract particular date/data

From: <Richard.Cotton_at_hsl.gov.uk>
Date: Fri, 02 May 2008 12:15:51 +0100


> 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}}

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. Received on Fri 02 May 2008 - 11:18:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 02 May 2008 - 11:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive