简体   繁体   中英

I am new to r. How can I convert a data frame variable value from a number to a name? See code below

>may_jfk<-may_df%>%filter(origin=="JFK")
>may_jfk
> str(may_jfk)
'data.frame':   9397 obs. of  4 variables:
 $ origin  : chr  "JFK" "JFK" "JFK" "JFK" ...
 $ flight  : int  413 701 5716 715 315 1169 303 1657 203 195 ...
 $ month   : int  5 5 5 5 5 5 5 5 5 5 ...
 $ dep_time: int  9 537 555 557 603 605 605 605 621 621 ...

How can I change $month from "5" to "May"?

We can use month.abb in base R

may_jfk$month <- month.abb[may_jfk$month]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM