【发布时间】:2021-10-17 12:47:34
【问题描述】:
我有数据框df,我展示了其中的前几行
age region graduate salary
19 "North" "no" 21000
25 "South" "yes" 24000
23 "Center" "yes" 23000
30 "South" "no" 25000
其中region 可以是“北”、“中”或“南”,graduate 可以是“是”或“否”。我的目标是执行以下分析
library("corrplot")
df <- data.frame(age=c(19,25,23,30), region=c("North","South","Center","South"), graduate=c("no","yes","yes","no"), salary=c(21000,24000,23000,25000))
corrplot(cor(df), method='number')
但我收到以下错误:
Error in cor(df) : 'x' must be numeric.
这里有什么解决方案? 是不是一定要把原来的数据库改成下面这样的
age region-North region-Center region-South graduate-yes graduate-no salary
19 1 0 0 0 1 21000
25 0 0 1 1 0 24000
23 0 1 0 1 0 23000
30 0 0 1 0 1 25000
然后重新启动代码?或者我可以直接在corrplot的方法中操作吗?目标是了解哪些变量对salary 的影响最大。
【问题讨论】:
-
我认为您可以使用方差分析(ANOVA)来了解不同地区和毕业生的平均工资是否存在差异,而不是计算相关性
标签: r correlation categorical-data