【发布时间】:2022-01-20 15:27:18
【问题描述】:
我想我正在做的事情几乎与这个问题完全一样:reshape wide to long using prefix as id in R
但如果可能的话,我很想使用 tidyverse。
我有这个数据。这些列是两组几乎相同的变量,前面有一个“pre”或“post”。
data<-structure(list(PreConfidence_NonMarginal = c(3, 1, 2, 4, 4, 5,
5, 4, 4, 5, 5, 1, 2, 3, 3, 4, 3, 4), PreConfidenceMarginal = c(1,
1, 1, 3, 3, 4, 4, 4, 4, 4, 2, 1, 1, 1, 2, 3, 2, 1), PreConfidenceInstruments = c(3,
2, 2, 5, 4, 5, 5, 4, 4, 5, 5, 1, 3, 3, 3, 4, 3, 3), PreConfidenceSutures = c(2,
1, 2, 4, 2, 5, 3, 4, 4, 4, 5, 1, 2, 2, 3, 4, 3, 3), PreFamiliarAnatomy = c(3,
3, 2, 5, 3, 4, 4, 4, 4, 5, 4, 1, 2, 3, 3, 3, 2, 3), PreEfficient = c(1,
1, 1, 3, 3, 3, 3, 4, 3, 4, 5, 1, 1, 1, 4, 3, 2, 3), PostConfidence_NonMarginal = c(4,
3, 3, 4, 4, 5, 5, 4, 5, 5, 5, 3, 3, 3, 4, 4, 4, 4), PostConfidenceMarginal = c(2,
2, 2, 4, 4, 4, 4, 4, 5, 4, 3, 3, 1, 3, 4, 3, 3, 3), PostConfidenceInstruments = c(3,
3, 4, 5, 4, 5, 4, 4, 5, 5, 5, 3, 3, 3, 5, 4, 4, 3), PostConfidenceSutures = c(3,
3, 4, 4, 3, 5, 3, 5, 5, 4, 5, 3, 3, 3, 5, 4, 3, 3), PostFamiliarAnatomy = c(3,
4, 2, 5, 3, 4, 4, 4, 4, 5, 4, 3, 3, 3, 4, 4, 3, 4), PostEfficient = c(2,
2, 2, 4, 3, 4, 4, 5, 3, 4, 5, 3, 2, 3, 4, 4, 2, 4)), row.names = c(NA,
-18L), class = c("tbl_df", "tbl", "data.frame"))
而且我希望旋转更长的时间,以便列是“pre”和“post”,而变量名的其余部分作为新的行标题。理想情况下,结果应该是这样的:
任何帮助将不胜感激,谢谢!
【问题讨论】: