从大量的调查回复数据集中,我必须构建按特定变量的递减值排序的表格。例如,这是我创建的一张表:
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")
这会产生一个 6x4 双精度矩阵,其中列名称为 You、Your.Staff、All.Principals、All.Staff。现在,在我运行 xtable 之前,我需要按 Your.Staff 的降序对 tab.L6 进行排序。
我尝试使用 plyr 和 data.table 以及基本的排序和排序功能。如果我执行以下
tL6 <- as.data.frame(tab.L6)
table.L6 <- arrange(tL6, desc(Your.Staff))
我最终得到了所需的排序但缺少行名。
You Your.Staff All.Principals All.Staff
1 5 5.0 3.8 3.8
2 5 4.5 4.0 3.9
3 5 4.5 3.8 3.6
4 5 4.0 3.5 3.7
5 5 4.0 3.6 3.9
6 4 4.0 3.4 3.7
有没有办法对行名进行排序和保留?