0
我的数据帧:分配动态变量来重塑idvar
structure(list(NEWSEC = c("A1", "A1", "A1", "A1", "A2", "A2",
"A2"), tiles = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L), .Label = c("1st",
"2nd", "3rd", "4th"), class = c("ordered", "factor")), AVG = c(360,
594, 868, 1534, 349, 592, 861)), .Names = c("NEWSEC", "tiles",
"AVG"), row.names = c(NA, 7L), class = "data.frame")
它看起来像这样:
NEWSEC tiles AVG
1 A1 1st 360
2 A1 2nd 594
3 A1 3rd 868
4 A1 4th 1534
5 A2 1st 349
6 A2 2nd 592
7 A2 3rd 861
当我使用从基础R重塑功能
reshape(df, idvar = "NEWSEC", timevar = "tiles", direction = "wide")
这工作完全好吧...但我的数据框是通过闪亮的应用程序输入动态生成的,而不是我选择的市场或C,而不是NEWSEC ATEGORY。通常我将输入变量分配给一个对象,并在我的函数中引用该对象。例如:
sec <- input$colvar
但是,当我尝试类似的方法与重塑它不工作。我的代码到目前为止:
reshape(df, idvar = sec, timevar = "tiles", direction = "wide").
我也尝试粘贴变量秒引号,但没有奏效。
reshape(df, idvar = paste(""",sec,""", sep = "), timevar = "tiles", direction = "wide").
我不知道这是否正确...但只是尝试过。
许多感谢详细的解答。我认为它是有效的。由于我的应用程序有太多的输入和过滤器以及支持文件,我错过了它。再次感谢。 – Apricot