R - convert data.frame to multi-dimensional matrix

前端 未结 3 1714
终归单人心
终归单人心 2021-01-28 03:30

From example from a data.frame:

x = data.frame(c(1,1,2,2,3,3), c(1,2,1,2,1,2), c(1,1,1,2,2,2), c(12,14,22,24,34,28))
colnames(x)=c(\"Store\",\"Dept\",\"Year\",\"         


        
3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-28 03:56

    Something like :

    tapply(X = x[["Sales"]], INDEX = x[setdiff(names(x), "Sales")], FUN = identity)
    

    could work, but it is a bit strange to use tapply with the identity function.

提交回复
热议问题