Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何一次对所有因子级别进行排序,而不是单独排序_R_Factors - Fatal编程技术网

R 如何一次对所有因子级别进行排序,而不是单独排序

R 如何一次对所有因子级别进行排序,而不是单独排序,r,factors,R,Factors,我正在对一项调查进行分析,大多数问题(167个问题中的105个)的排名在1到10之间,如果没有填写,排名在99999之间。我将数据集加载到R中,并用这105个问题制作了一个数据框。当我这样做时,我发现数据类型不正确。他们都是dbl。因此,我首先使用(数据集=调查)更改了数据类型: 我知道一种单独重新排列级别的方法,例如: survey %>% group_by(v2_a)%>% summarize(count = n()) survey$v2_a <- factor(surv

我正在对一项调查进行分析,大多数问题(167个问题中的105个)的排名在1到10之间,如果没有填写,排名在99999之间。我将数据集加载到R中,并用这105个问题制作了一个数据框。当我这样做时,我发现数据类型不正确。他们都是dbl。因此,我首先使用(数据集=调查)更改了数据类型:

我知道一种单独重新排列级别的方法,例如:

survey %>% group_by(v2_a)%>% summarize(count = n())
survey$v2_a <- factor(survey$v2_a, levels = c("1","2", "3", "4","5","6","7","8","9","10","No answer"))
survey$v2_b <- factor(survey$v2_b, levels = c("1","2", "3", "4","5","6","7","8","9","10","No answer"))
survey$v2_c <- factor(survey$v2_c, levels = c("1","2", "3", "4","5","6","7","8","9","10","No answer"))
...

survey$v2\u a提供给
lappy
的任何附加参数都将添加到函数参数中,因此类似于

survey[] <- lapply(survey,factor,levels=c(1:10,"no answer"))

survey[]提供给
lappy
的任何附加参数都将添加到函数参数中,因此如下所示

survey[] <- lapply(survey,factor,levels=c(1:10,"no answer"))

survey[]你不必感谢我,接受答案就足够了。(但这种情绪是值得赞赏的)你不需要感谢我,接受答案就足够了。(但这种情绪值得赞赏)
survey <- factor(survey, levels = c("1","2", "3", "4","5","6","7","8","9","10","No answer"))
survey[] <- lapply(survey,factor,levels=c(1:10,"no answer"))
ffun <- function(x) return(factor(x,levels=c(1:10,"no answer")))
survey[] <- lapply(survey,ffun)