[R] Working with temporal data

Petr Klasterecky klaster at karlin.mff.cuni.cz
Thu Feb 15 15:18:24 CET 2007


Sérgio Nunes napsal(a):
> Hi,
> 
> I have several files with data in this format:
> 
> 20070102
> 20070102
> 20070106
> 20070201
> ...
> 
> The data is sorted and each line represents a date (YYYYMMDD). I would
> like to analyze this data using R. For instance, I would like to have
> a histogram by year, month or day.
> 
> I've already made a simple Perl script that aggregates this data but I
> believe that R can be much more powerful and easy on this kind of
> work.
> 
> Any suggestions on where to start?
> 
> Thanks in advance,
> Sérgio Nunes

Analysing a particular day is easy - just call e.g. 
hist(your.variable[day==20070101])
if 'day' contains the date stored as an integer.

If you want to do this for all days probably you mmight use a loop 
through unique(day)

Finally, to do a monthly/yearly analysis, just create 'month' and 'year'
month <- trunc(day/100)
year <- trunc(day/10000)

HTH
Petr Klasterecky
-- 
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic



More information about the R-help mailing list