[R] length() of vector after using strptime()
David Whiting
david.whiting at ncl.ac.uk
Fri Oct 10 19:09:25 CEST 2003
Hi,
I am trying to parse a date (that is read in as a factor) and add it
to a dataframe. The length of the parsed date is shorter than the
length of unparsed date and I therefore cannot add it to the dataframe:
> x
[1] 20030807 20030807 20030807 20030808 20030809 20030809 20030809 20030809
[9] 20030808 20030808 20030809 20030808 20030808 20030819 20030819 20030821
.
.
.
[129] 20030808 20030805 20030726 20030810 20030805 20030811 20030816 20030818
[137] 20030811
> length(x)
[1] 137
> xParsed <- strptime(as.character(x), "%Y%m%d")
>
> xParsed
[1] "2003-08-07" "2003-08-07" "2003-08-07" "2003-08-08" "2003-08-09"
[6] "2003-08-09" "2003-08-09" "2003-08-09" "2003-08-08" "2003-08-08"
.
.
.
[131] "2003-07-26" "2003-08-10" "2003-08-05" "2003-08-11" "2003-08-16"
[136] "2003-08-18" "2003-08-11"
> length(xParsed)
[1] 9
>
> dta$dateint <- xParsed
Error in "$<-.data.frame"(`*tmp*`, "dateint", value = xParsed) :
replacement has 9 rows, data has 137
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status
major 1
minor 8.0
year 2003
month 10
day 08
language R
Can someone tell me what I'm doing wrong?
Thanks.
--
David Whiting
Dar es Salaam, Tanzania
More information about the R-help
mailing list