简体   繁体   English

我是 r 的新手。 如何将数据框变量值从数字转换为名称? 请参阅下面的代码

[英]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"?如何将 $month 从“5”更改为“May”?

We can use month.abb in base R我们可以在base R中使用month.abb

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我是 r 的新手。我试图通过使用 for 循环使我的代码不那么复杂 - I am new to r. I am trying to make my code less complicated by using a for loop 在 R 中将 excel 表编码为数据框。我不想导出表,我想将其编码为 R 中的数据框 - Code an excel table into a data frame in R. I don't want to export the table, I would like to code it as a data frame in R 如何使用基于现有数据框的值创建新数据框,并使用R中的数字向量创建范围。 - How to create a new dataframe with values based on existing data frame and range from numeric vectors in R. 如何使用 R Studio 中旧数据框的精确行创建新数据框? - how can I create a new data frame using exact rows from the old data frame in R Studio? R的新手。我正在尝试从mlbench软件包的Glass $ Fe中将0.00值添加.01。 - New to R. I am trying add .01 the 0.00 values in the Glass$Fe from the mlbench package 如何将此表变成数据框? 我正在使用 R。 试图得到它的方差分析表 - How do I make this table into a data frame? I'm using R. Trying to get the ANOVA table for it R。 我正在尝试将我的数据框子集几十年。 因此,我想通过使用列的值进行子集化 - R. I am trying to subset my data frame by decades. Therefore I want to subset by using values of a column 在我使用来自原始数据集的信息创建新数据集时,如何简化此代码 (r)? - How can I simplify this code (r) in which I am using information from an original data set to create a new dataset? 如何找到数据框中完整案例的数量并使用 R 生成仅包含列的指定值的小计的新数据框? - How do I find the number of complete cases in a data frame and produce a new data frame with only subtotals for a specified value of a column using R? 如何从R上的数据框中删除特定行。 - How to delete specific rows from a data frame on R.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM