R 工资中的方差分析
ANOVA in R Salaries
你能告诉我我做错了什么吗?我正在尝试 运行 对 5 支 NBA 球队的薪水进行方差分析。我试图将薪水更改为一个因素,但我怀疑我错过了一步。我非常感谢你的回应。请看下面。
> read.csv("~/DATA630/ANOVANBATeams.csv")
Pistons Wizards Cavaliers Clippers Thunder
1 7,000,000 16,957,900 18,000,000 21,468,695 17,832,627
2 3,650,000 5,497,625 21,108,899 6,938,750 4,663,129
3 2772440 4,440,000 5,982,375 10,188,750 2,757,500
4 5,479,933 2,123,733 4,525,000 1,448,490 2,184,960
5 1,208,325 1,448,490 903,456 613,478 966,800
> > read.csv("~/DATA630/ANOVANBATeams.csv", header = TRUE)
Error: unexpected '>' in ">"
> salary <- read.csv("~/DATA630/ANOVANBATeams.csv", header = TRUE)
> salary$Team = as.factor(salary$Team)
Error in `$<-.data.frame`(`*tmp*`, "Team", value = integer(0)) :
replacement has 0 rows, data has 5
听起来您想要以团队名称作为因素的长格式数据。试试这个:
salary <- read.csv("~/DATA630/ANOVANBATeams.csv", header=T)
Teams <- colnames(salary)
salary2 <- reshape(salary, direction="long", varying=list(Teams), ids=Teams)
colnames(salary2)[2:3] <- c("Salary", "Team")
工资中的逗号使 R 无法将它们正确转换为数字,因此我们可以使用 gsub()
.
删除它们
salary2$Salary <- as.numeric(gsub(",", "", salary2$Salary)))
salary2$Team <- as.factor(salary2$Team)
进行方差分析。
aov(Salary ~ Team, data=salary2)
你能告诉我我做错了什么吗?我正在尝试 运行 对 5 支 NBA 球队的薪水进行方差分析。我试图将薪水更改为一个因素,但我怀疑我错过了一步。我非常感谢你的回应。请看下面。
> read.csv("~/DATA630/ANOVANBATeams.csv")
Pistons Wizards Cavaliers Clippers Thunder
1 7,000,000 16,957,900 18,000,000 21,468,695 17,832,627
2 3,650,000 5,497,625 21,108,899 6,938,750 4,663,129
3 2772440 4,440,000 5,982,375 10,188,750 2,757,500
4 5,479,933 2,123,733 4,525,000 1,448,490 2,184,960
5 1,208,325 1,448,490 903,456 613,478 966,800
> > read.csv("~/DATA630/ANOVANBATeams.csv", header = TRUE)
Error: unexpected '>' in ">"
> salary <- read.csv("~/DATA630/ANOVANBATeams.csv", header = TRUE)
> salary$Team = as.factor(salary$Team)
Error in `$<-.data.frame`(`*tmp*`, "Team", value = integer(0)) :
replacement has 0 rows, data has 5
听起来您想要以团队名称作为因素的长格式数据。试试这个:
salary <- read.csv("~/DATA630/ANOVANBATeams.csv", header=T)
Teams <- colnames(salary)
salary2 <- reshape(salary, direction="long", varying=list(Teams), ids=Teams)
colnames(salary2)[2:3] <- c("Salary", "Team")
工资中的逗号使 R 无法将它们正确转换为数字,因此我们可以使用 gsub()
.
salary2$Salary <- as.numeric(gsub(",", "", salary2$Salary)))
salary2$Team <- as.factor(salary2$Team)
进行方差分析。
aov(Salary ~ Team, data=salary2)