用于转换表的dplyr或tidyr用法

时间:2018-05-07 20:16:08

标签: r dplyr tidy

我有这个数据框

group = c("A","B","C")
num = c(1,2,3)
calc1 = c(4,5,6)
calc2 = c(7,8,9)
temp = c("GG","HH","KK")
temp2 = c("ll","pp","rr")
library(dplyr)
dat =data.frame(group = group, num = num , calc1 = calc1, calc2 = calc2, temp = temp, temp2 = temp2)
dat

  group num calc1 calc2 temp temp2
1     A   1     4     7   GG    ll
2     B   2     5     8   HH    pp
3     C   3     6     9   KK    rr

并且我想重新排列数据,因此表格看起来像是一个公制列,其中包含num,calc1和calc2,而columnw的值是group,并删除了临时列:

metric      A      B    C
num         1      2    3
calc1       4      5    6 
calc2       7      8    9

最好的方法是什么?

1 个答案:

答案 0 :(得分:4)

删除 CommonSQLiteUtilities.logDatabaseInfo(helper.getWitableDatabase()); 列,temp,然后gather

spread