0

I am trying to run a simple regression in R (mac OSX), to see if the level of an environmental certification has improved over time - among other things. The data I downloaded offers a level from 1-4, and the dates in 1-Mar-12 format. I can't seem to get R to convert the dates, and I keep getting the same error message. The variables are the same length.

$ certification_date: chr  "1-Aug-11" "1-Aug-11" "1-Aug-11" "1-Jul-11" ...

jday<-as.Date('certification_date',format='%d-%b-%y',"%j")
mod <- lm(Level_number ~ jday, data=data)

Error in model.frame.default(formula = Level_number ~ jday, data = data,  : 
  variable lengths differ (found for 'jday')

summary(jday)
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
  NA      NA      NA      NA      NA      NA     "1" 

Can anyone spot where I've gone wrong?

juba
  • 47,631
  • 14
  • 113
  • 118

1 Answers1

0

You should remove the quotes around certification_date as mentioned in the comment, But %b is the abbreviated month name in the current locale. So you can get another problem with your locals. Here I present a independent-local solution:

## get your current local time
loc <- Sys.getlocale('LC_TIME')  
## set the local to english , since %b is local dependent 
Sys.setlocale('LC_TIME','ENGLISH')
jday <-as.Date(certification_date,format='%d-%b-%y',"%j")
Sys.setlocale('LC_TIME',loc)

The result is:

jday
[1] "2011-08-01" "2011-08-01" "2011-08-01" "2011-07-01"
agstudy
  • 119,832
  • 17
  • 199
  • 261