【问题标题】:Convert answers (from a survey in a dataframe) into numerical value将答案(来自数据框中的调查)转换为数值
【发布时间】:2022-01-08 11:10:16
【问题描述】:

我进行了一项调查,答案包括“非常重要”、“中等重要”、“一点也不”等答案。我将调查表放在我放在 R 上的 Excel 表中。

我想使用 ANOVA(单向)测试来检查一个答案与回答调查的人的性别之间的联系。

但我在使用聚合函数时找不到平均值,因为调查的答案不是数字。我需要将非常重要的转换为 5,非常重要的转换为 4,等等...

这怎么可能? 感谢您的帮助和时间。

enter image description here

enter image description here

【问题讨论】:

标签: r data-conversion survey


【解决方案1】:

有几种方法可以做到这一点。首先想到的是将字符向量转换为有序因子,然后转换为如下数字:

# suppose your scores vector looks like this:
scores <- c('Extremely Important', 'Very Important', 'Moderately Important', 'Sort of Important', 'Not Important')

as.numeric(factor(scores, levels = c('Not Important', 'Sort of Important', 'Moderately Important', 'Very Important',  'Extremely Important')))

levels 的第一个值将被赋值为 1,...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    • 2020-05-20
    • 2020-04-03
    相关资源
    最近更新 更多