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