[R] Date variable error
Ben Bolker
bbolker at gmail.com
Tue Dec 14 17:11:49 CET 2010
<Kurt_Helf <at> nps.gov> writes:
>
> Greetings
> In attempting to create a date variable based on month (e.g.,
> February, April, etc.) and year (e.g., 2006) data, wherein I converted
> Month to a factor with Jan=1...Dec=12, I used the following command:
>
> data$Date<-mdy.date(month=data$Month,day=15,year=data$Year)
>
> however, I get a message "Error: trunc not meaningful for factors"
Have you tried
data$Date<-mdy.date(month=as.numeric(data$Month),day=15,year=data$Year)
(I like with() or transform() for making these cleaner:
data <- transform(data,Date=mdy.date(month=as.numeric(Month),day=15,year=Year))
More information about the R-help
mailing list