[R] Associating the day of week to a daily xts object

Victor vdemart at gmail.com
Mon Mar 7 10:05:59 CET 2011


I have the following xts objetct "temp" 
 
> str(temp)
An ‘xts’ object from 2010-12-26 to 2011-03-05 containing:
  Data: num [1:70, 1] 2.95 0.852 -0.139 1.347 2.485 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr "t_n"
  Indexed by objects of class: [POSIXct,POSIXt] TZ: GMT
  xts Attributes:  
 NULL


> temp
                  t_n
2010-12-26  2.9500000
2010-12-27  0.8520833
2010-12-28 -0.1390625
...........

I would like to associate another column with the day of week in the form of 1=Mon, 2=Tue, ..., 7=Sun
in order to obtain:

>newtemp

                  t_n                     dow
2010-12-26  2.9500000    7
2010-12-27  0.8520833    1
2010-12-28 -0.1390625    2
..............

How could make this in the shortest (and elegant?) way?

Ciao from Rome
Vittorio



More information about the R-help mailing list