基本上我的问题是我想要运行PCA分析,但我的数据结构不正确。希望这张图片可以让你理解我的意思:
trial.one.two <- na.omit(trial.one.one)
head(trial.one.two)
v79 v81 v82 Q.One Q.Two Q.Three
2 Disagrees a little Agrees a little Disagrees a little 3 2 3
3 Agrees a lot Agrees a lot Disagrees a little 1 1 3
4 Agrees a little Disagrees a lot Disagrees a lot 2 4 4
5 Agrees a lot Agrees a lot Disagrees a lot 1 1 4
6 Agrees a little Agrees a lot Agrees a little 2 1 2
8 Agrees a lot Agrees a little Agrees a lot 1 2 1
我正在使用的数据是在5000多名个人中进行的一项调查,我想知道有多少人回答过例如“同意很多”:2253,“同意一点”:2005年等。 我需要以下列方式分配数据:
1“很多人同意” 2“同意一点” 3“不一致” 4“不同意”
其中1是组件1,2是组件2,依此类推,基本上我想运行PCA。
任何人都可以引导我进入我应该做的事情吗?
---------- UPDATE -------------
我实施后:
convert.factor <- function(val){
if(val == "Agrees a lot"){
return(1)
} else if(val == "Agrees a little") {
return(2)
} else if(val == "Disagrees a little") {
return(3)
} else if(val == "Disagrees a lot") {
return(4)
}
}
trial.one.two$v79 <- sapply(trial.one.two$v79, convert.factor)
trial.one.two$v81 <- sapply(trial.one.two$v81, convert.factor)
trial.one.two$v82 <- sapply(trial.one.two$v82, convert.factor)
head(trial.one.two)
v79 v81 v82 Q.One Q.Two Q.Three
2 3 2 3 3 2 3
3 1 1 3 1 1 3
4 2 4 4 2 4 4
5 1 1 4 1 1 4
6 2 1 2 2 1 2
8 1 2 1 1 2 1
答案 0 :(得分:0)
你可以按照
的方式做点什么convert.factor <- function(val){
if(val == "Agrees a lot"){
return(1)
} else if(val == "Agrees a little") {
return(2)
} else if(val == "Disagrees a little") {
return(3)
} else if(val == "Disagrees a lot") {
return(4)
}
}
trial.one.two$v79 <- sapply(trial.one.two$v79, convert.factor)
trial.one.two$v81 <- sapply(trial.one.two$v81, convert.factor)
trial.one.two$v82 <- sapply(trial.one.two$v82, convert.factor)
或者,如果您只是在寻找人们回答每个类别的频率,您可以执行以下操作:
table(trial.one.two$v79)
请注意,在这种情况下,没有理由首先转换变量。