I have a vector within an R dataframe wich literally contains an abbreviation for the months in a year in the form (JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC) and I want to replace them for their traditional equivalent [1:12]
came up with the following ideas, all of which give a vector filled with not available (NA) values.
replace(df$month, df$month == 'JAN', '01')
df$month <- if(df$month == "JAN") '01'
df$month <- match(df$month,month.abb)
the first two only make NA values were JAN was, the third one makes all months NA values
Any ideas why this isn't working, and how to get it to work?
df$month
is a string and not a factor already. – jraabx
is your input vector then trymatch(x, toupper(month.abb))
– G. Grothendieck?toupper
– G. Grothendieck