[R] Date problem
ggrothendieck at gmail.com
Tue Mar 14 20:35:16 CET 2006
On 3/14/06, natalia norden <norden at cict.fr> wrote:
> I have some "stupid" problems managing "date" data.
> I have a colomn "date", which I converted from a character representation:
> for example:
> For one part of the analysis, I'm interested only in the month and the
> year, so I did:
> This returns me "02/06", but this is an object of class "character" and
> I can't convert it into an object of class "Date". Doing
> strptime(m.y,format="%m/%y") or as.Date(m.y,format="%m/%y") returns me NA
> How can a convert this colomn "m.y" in a Date class?
> Actually, I need it to plot fruiting data against time (month and year).
> Because I have many values of seeds in a month, I used the function tapply:
> But plot(x=names(seeds),y=seeds) doesn't work. Does anyone know an
> easier way?
Are these time series? If so, you could use the zoo package:
seeds <- zoo(1:100, as.Date("2000-01-01") + 0:99) # test data
seeds.mon <- aggregate(seeds, as.Date(as.yearmon(time(seeds))), sum)
or if seeds is not a time series, i.e. does not have unique dates:
seeds <- 1:100
dd <- rep(as.Date("2000-01-01") + 0:49, 2)
seeds.mon <- aggregate(zoo(seeds), as.Date(as.yearmon(dd)), sum)
More information about the R-help