![](/img/trans.png)
[英]How to remove rows Inf from a specific column in a dataframe using Tidyverse in R?
[英]Using R & readr from Tidyverse: How to Import dataframe as Factor and with Labels
我正在使用 Tidyverse 中的 R(-cran) 和readr
庫。 我有一個來自 .csv 文件的特征(列)是因素,例如性別 = c(0,1)。
問。 如何將數據導入為帶標簽的因子,使它們更有意義,例如:
df.csv = c("男",0,1,0,1,0)
df <- read_csv("df.csv",
col_types = cols(male = col_factor(levels = c("0","1"),
labels = c("F","M")))
但是,我收到錯誤消息:
Error in col_factor(levels = c("0", "1"), labels = c("F", "M")) :
unused argument (labels = c("F", "M"))
但是,我想要:0="F" 和 1="M"。
這是一種方法:
df <- read_csv("df.csv",
col_types = cols(male = col_factor(levels = c("0","1"))))
# Followed by
df$column = factor(df$column, labels=c("F","M"))
str(df)
tibble [3,656 × 1] (S3: tbl_df/tbl/data.frame)
$ 男性:因子 w/ 2 個級別“F”、“M”:2 1 2 1 1 1 1 1 2 2 ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.