Reputation: 21
I have a df month column like this:
"09" "09" "04" "01" "04" "10"
And I am trying to convert them to "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
I have tried this
df$months <- month.abb[df$month]
and mymonths <- c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") df$months <- mymonths[ df$month ]
but my output from the both is:
NA NA NA NA NA NA
Upvotes: 0
Views: 48
Reputation: 887048
We need to convert to integer
so that it can be used as position index to return the corresponding values of month.abb in that position
month.abb[as.integer(df$month)]
Upvotes: 2