【问题标题】:Change Numeric Variables to be Categorical in R [duplicate]在R中将数值变量更改为分类[重复]
【发布时间】:2023-03-22 12:37:01
【问题描述】:

这里又短又甜……

我在 R 中分析的数据框中有邮政编码。

R 将它们作为数字变量读取。如何让 R 将这些邮政编码(例如 20001)作为 categorical 变量读取。

【问题讨论】:

标签: r dataframe type-conversion numeric categorical-data


【解决方案1】:

只是让我的评论成为答案

你可以使用

data$ZIP <- as.character(data$ZIP) 

data$ZIP <- as.factor(data$ZIP)

取决于您喜欢使用的变量类型。

【讨论】:

    猜你喜欢
    • 2019-09-07
    • 1970-01-01
    • 2014-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 2021-08-26
    • 1970-01-01
    相关资源
    最近更新 更多