survey_B <- data.frame("q1" = c(5, 3, 2, 7, 1, 9),
"q2" = c(4, 2, 2, 5, 1, 10),
"q3" = c(2, 1, 4, 2, 9, 10),
"q4" = c(10, 5, 2, 10, 4, 2),
sd_B2 <- t(apply(survey_B, 2, function(x) x/sd(x)))
mean_B2 <- t(apply(survey_B, 2, function(x) x/mean(x)))
for(i in 1:nrow(survey_B)) {
for(j in 1:ncol(survey_B)) {
survey_B[i,j] = survey_B[i,j]-mean_B2[i,j] / sd_B2[i,j]
}
}
我想通过使用 for 循环来标准化我的数据框。我得到了列的平均值和标准差,但我不能将平均值与标准差分开。我总是收到“超出范围”的错误消息。
有人可以给我建议吗?