Re: [R] Odd behaviour of as.POSIXct

2011-07-16 Thread Hadley Wickham
> Also, if we make days a list, the class attributes are kept when looping > over the list, ie. > > days<- list( as.Date( c("2000-01-01", "2000-01-02") ) ) Do you realise that that's a list with length one? I suspect you want days <- as.list( as.Date( c("2000-01-01", "2000-01-02") ) ) for (day i

Re: [R] Odd behaviour of as.POSIXct

2011-07-16 Thread Johannes Egner
Duncan, thanks very much -- this explains the behaviour. Also, if we make days a list, the class attributes are kept when looping over the list, ie. days<- list( as.Date( c("2000-01-01", "2000-01-02") ) ) for (day in days) { # class(day) <- class(days) print(as.POSIXct(day)) } works as expect

Re: [R] Odd behaviour of as.POSIXct

2011-07-15 Thread Duncan Murdoch
On 15/07/2011 12:15 PM, Johannes Egner wrote: Dear all, how come the first loop in the below fails, but the second performs as expected? days<- as.Date( c("2000-01-01", "2000-01-02") ) for(day in days) { as.POSIXct(day) } "day" in the loop above is an integer without a class, it's not a

Re: [R] Odd behaviour of as.POSIXct

2011-07-15 Thread B77S
day doesn't exist? That would be the 1st problem. Johannes Egner wrote: > > Dear all, > > how come the first loop in the below fails, but the second performs as > expected? > > days <- as.Date( c("2000-01-01", "2000-01-02") ) > > for(day in days) > { > as.POSIXct(day) > } > > for( n in

[R] Odd behaviour of as.POSIXct

2011-07-15 Thread Johannes Egner
Dear all, how come the first loop in the below fails, but the second performs as expected? days <- as.Date( c("2000-01-01", "2000-01-02") ) for(day in days) { as.POSIXct(day) } for( n in 1:length(days) ) { show(as.POSIXct(days[n])) } Many thanks, Jo [[alternative HTML version