Skip to content
Prev 67232 / 398502 Next

Assigning "dates" attribute

On Thu, 7 Apr 2005 08:26:41 -0700 (PDT) JTW wrote:

            
The error message is pretty informative, the assignment needs a named
list, e.g.:

R> x <- 1:10
R> attributes(x) <- list(foo = letters[1:10])
R> x
 [1]  1  2  3  4  5  6  7  8  9 10
attr(,"foo")
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"

Note, that this will strip off all other attributes. To add one
attribute, you can do

R> attr(x, "bar") <- LETTERS[1:10]
R> x
 [1]  1  2  3  4  5  6  7  8  9 10
attr(,"foo")
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
attr(,"bar")
 [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"

Furthermore, the data you describe look like a time series. So you might
want to store the data as a time series. For time series with a date
attribute of class "Date", look at the zoo package.
Z