Convert months mmm to numeric

前端 未结 4 1803
粉色の甜心
粉色の甜心 2020-12-09 08:07

I have been given a csv with a column called month as a char variable with the first three letters of the month. E.g.:

\"Jan\", \"Feb\",\"Mar\",...\"Dec\"
         


        
4条回答
  •  北海茫月
    2020-12-09 08:37

    A couple of options using:

    vec <- c("Jan","Dec","Jan","Apr")
    

    are

    > Months <- 1:12
    > names(Months) <- month.abb
    > unname(Months[vec])
    [1]  1 12  1  4
    

    and/or

    > match(vec, month.abb)
    [1]  1 12  1  4
    

提交回复
热议问题