我有一份清单,内容不同,时间段不同。我希望将这些类合并为一列。
我尝试写:
test5<-unite(test5,"ENGELSKA",c("MARKEN200","MARKENGENG05","MARKEN1201"))
但是无论出于何种原因,R都无法找到我的列,即使它们已正确指定。我宁愿不要诉诸于列号(尽管这样做确实可行),因为我将需要多次使用“ unite”命令,并且由于使用索引号似乎会使这一点搞砸了。
我以前不得不重塑数据并删除列名中的结果句点。可能与此有关。我尝试按如下所示用反引号和空格编写列名,但没有任何效果。
数据快照:
structure(list(`MARKEN200 ` = structure(c(8L, NA, NA, NA,
NA, NA), .Label = c("A ", "B ", "C ", "D ", "E ", "G ",
"MVG", "VG "), class = "factor"), `MARKEN1201 ` = structure(c(NA,
NA, 8L, 7L, NA, 8L), .Label = c("A ", "B ", "C ", "D ", "E ",
"G ", "MVG", "VG "), class = "factor"), `MARKENGENG05 ` = structure(c(NA,
1L, NA, NA, 3L, NA), .Label = c("A ", "B ", "C ", "D ", "E ",
"G ", "MVG", "VG "), class = "factor")), reshapeWide = list(
v.names = "QUAL_RATING", timevar = "SEL_CRITERION", idvar = "PNR",
times = structure(3:1, .Label = c("BI ", "BII ", "HP "
), class = "factor"), varying = structure(c("QUAL_RATING.HP ",
"QUAL_RATING.BII ", "QUAL_RATING.BI "), .Dim = c(1L, 3L
))), row.names = c(1L, 5L, 9L, 12L, 15L, 18L), class = "data.frame")
答案 0 :(得分:0)
当我以前尝试解决此问题时,我用引号将空格+反引号引起来。一旦我只使用反引号/空格尝试了代码,代码便真正起作用了:
test5<-unite(test5,"ENGELSKA",c(`MARKEN200 `,`MARKENGENG05 `,`MARKEN1201 `))
我不太赞成这些列名,但是我现在可以使用它。