On Wed, 12 Nov 2003, RINNER Heinrich wrote:
> I am using R 1.8.0, under Windows XP.
>
> What I want to do is a date conversion of a character column of a data
frame
> and assign the result as a new column.
>
> Simple example:
> > x <-
data.frame(a=c("yesterday","today","tomorrow"),
b=I(c("20031111",
> "20031112", "20031113")))
> # convert x$b from character to date:
> > strptime(x$b, format="%Y%m%d")
> [1] "2003-11-11" "2003-11-12" "2003-11-13"
> # trying to make this a new column in x:
> > x$c <- strptime(x$b, format="%Y%m%d")
> Error in "$<-.data.frame"(`*tmp*`, "c", value =
strptime(x$b, format > "%Y%m%d")) :
> replacement has 9 rows, data has 3
>
> I have done this before (in R 1.7.0), and I am pretty sure this has been
> working then.
It was an undetected error then.
> What am I doing wrong here (has something changed concerning the value of
> strptime() in R 1.8.0)?
You need as.POSXIct, just as you always have. strptime gives a list of
length 9, and that does not go into a dataframe of 3 rows.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595