Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.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 在导出到xtable之前按特定变量对表进行排序_R_Latex - Fatal编程技术网

R 在导出到xtable之前按特定变量对表进行排序

R 在导出到xtable之前按特定变量对表进行排序,r,latex,R,Latex,从一个大的调查响应数据集中,我必须构建按特定变量的递减值排序的表。例如,我创建了一个表: t8 <- xtabs(meanq8 ~ respondent, data = bfk1) t13 <- xtabs(meanq13 ~ respondent, data=bfk1) t18 <- xtabs(meanq18 ~ respondent, data=bfk1) t23 <- xtabs(meanq23 ~ respondent, data=bfk1) t28 <

从一个大的调查响应数据集中,我必须构建按特定变量的递减值排序的表。例如,我创建了一个表:

t8  <- xtabs(meanq8 ~ respondent, data = bfk1)
t13 <- xtabs(meanq13 ~ respondent, data=bfk1)
t18 <- xtabs(meanq18 ~ respondent, data=bfk1)
t23 <- xtabs(meanq23 ~ respondent, data=bfk1)
t28 <- xtabs(meanq28 ~ respondent, data=bfk1)
t33 <- xtabs(meanq33 ~ respondent, data=bfk1)

tab.L6 <- rbind(t8, t13, t18, t23, t28, t33) 
rownames(tab.L6) <- c("I give teachers a sense of overall purpose", "I help clarify the specific meaning of the school's mission in terms of its practical implications for programs and instruction", "I communicate the school mission to staff and students", "I encourage the development of school norms supporting openness to change", "I help teachers understand the relationship between our school's mission and District initiatives", "I work toward whole-staff consensus in establishing priorities for school goals")

有没有办法排序和保留行名

为行名编制索引并在排序后添加行名如何

tab.L6 = as.data.frame(matrix(runif(24,1,100),6))
rownames(tab.L6) <- c("I give teachers...", "I help clarify...", "I communicate..", "I encourage...", "I help teachers...", "I work toward...")
names(tab.L6) = c('You','Your.Staff','All.Principals','All.Staff')
tab.L6$index = 1:6
tab.L6

vecnames = c("I give teachers...", "I help clarify...", "I communicate..", "I encourage...", "I help teachers...", "I work toward...")

(t2 = arrange(tab.L6, desc(Your.Staff)))
rownames(t2) = vecnames[t2$index]
t2
然后,您可以在导出表之前删除索引列:

t2$index = NULL
tab.L6 = as.data.frame(matrix(runif(24,1,100),6))
rownames(tab.L6) <- c("I give teachers...", "I help clarify...", "I communicate..", "I encourage...", "I help teachers...", "I work toward...")
names(tab.L6) = c('You','Your.Staff','All.Principals','All.Staff')
tab.L6$index = 1:6
tab.L6

vecnames = c("I give teachers...", "I help clarify...", "I communicate..", "I encourage...", "I help teachers...", "I work toward...")

(t2 = arrange(tab.L6, desc(Your.Staff)))
rownames(t2) = vecnames[t2$index]
t2
                         You Your.Staff All.Principals All.Staff index
I help teachers... 33.620593  94.174583       12.93681  60.34864     5
I work toward...   98.250119  84.166085       79.57018  89.76993     6
I help clarify...  85.478336  52.664455       71.82487  18.08677     2
I encourage...     55.972257  50.095689       55.96154  60.04199     4
I give teachers... 20.183314  28.812243       21.71087  29.02465     1
I communicate..     8.520616   3.409428       75.94298  56.98706     3
t2$index = NULL