有一个数据框:
tbl <- structure(list(t = c(1, 2, 3, 4, 5, 6), ak_b = c(909.021709977295,
957.828244741177, 1037.13886373248, 1122.55029956928, 1275.07072070641,
1415.38950815257), djk_b = c(2824.00501596013, 2975.62944634725,
3222.01914572632, 3487.36189890379, 3961.18824386354, 4397.10848122651
), ak_a = c(909.021709977295, 957.828244741177, 1037.13886373248,
1122.55029956928, 1275.07072070641, 1415.38950815257), djk_a = c(2824.00501596013,
2975.62944634725, 3222.01914572632, 3487.36189890379, 3961.18824386354,
4397.10848122651)), row.names = c(NA, -6L), class = "data.frame")
想把它变为如下形式:
t value class1 class2
1 909 ak b
2 2824 djk b
3 909 ak a
...
即,将列名根据_
拆分之后形成的字符作为class
,并对应至相应的value
上,请问大家有没有方便的解法呢?