Skip to content

Assigning "dates" attribute

2 messages · JTW, Achim Zeileis

JTW
#
Dear List,

I have a one-column data set in .csv format.

I used read.csv to import the data into R, as follows:

x <- read.csv("data.csv", header = TRUE, sep = ",")

The data points have a 'dates' attribute, which is in
a separatel .csv file.  I used the same command as
above to import it into R.

To assoicate the 'dates' attribute with the data
points, I did:
Which resulted in:

Error in "attributes<-"(`*tmp*`, value = date) :
attributes must be in a list

So then I did:
Again, got an error, though slightly different this
time:

Error in "attributes<-"(`*tmp*`, value = list(date)) :
attributes must be named

Any help is appreciated.
#
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