tags:

views:

180

answers:

1

Hello, Basically I want to know why as.Date(200322,format="%Y%W") gives me NA. While we are at it, I would appreciate any advice on a data structure for repeated cross-section (aka pseudo-panel) in R. I did get aggregate() to (sort of) work, but it is not flexible enough - it misses data on columns when I omit the missed values, for example. Specifically, I have a survey that is repeated weekly for a couple of years with a bunch of similar questions answers to which I would like to combine, average, condition and plot in both dimensions. Getting the date conversion right should presumably help me towards my goal with zoo package or something similar.

Any input is appreciated.

Cheers

Update: thanks for string suggestion, but as you can see in your own example, %W part doesnt work - it only identifies the year while setting the current day while I need to set a specific week (and leave the day blank).

+3  A: 

Use a string as first argument in as.Date() and select a specific weekday (format %w, value 0-6). There are seven possible dates in each week, therefore strptime needs more information to select a unique date. Otherwise the current day and month are returned.

> as.Date(paste("200947", "0", sep="-"), format="%Y%W-%w")
[1] "2009-11-22"
rcs
But why `format(as.Date("2003-06-02"),"%Y-%W")` gives `"2003-22"`, and `as.Date("2003-22","%Y-%W")` gives `"2003-11-23"` (month and day is from current date)
Marek
You have to specify the number of a weekday (`as.Date("2003-22-1","%Y-%W-%w")`), otherwise there is no unique result and the current day and month are returned.
rcs