将汇总的数据框%不存在%存在重塑为每行长数据框

时间:2019-05-29 11:10:18

标签: r dplyr reshape

我有一个包含5个变量的汇总数据框。在此数据帧中,没有二进制变量(存在/不存在),而是两个变量(D1,D0),它们根据以下各项的每种组合来反映存在事件(D1)或不存在事件(D0)的个体的百分比饮食(fDieta),温度(温度)和密度(fDensidad)。我需要将这些摘要数据转换为原始数据:每个原始数据都是个人。

mydata<- structure(list(D1 = c(17, 19, 24, 19, 17, 27, 20, 22, 34, 11, 12, 18, 15, 16, 19, 17, 17, 26, 5, 7, 10, 5, 9, 12, 10, 10, 15), D2 = c(83, 81, 76, 81, 83, 73, 80, 78, 66, 89, 88, 82, 85, 84, 81, 83, 83, 74, 95, 93, 90, 95, 91, 88, 90, 90, 85), fDieta = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("E0", "E1", "E2"), class = "factor"), fTemperatura = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L), .Label = c("T16", "T19", "T22"), class = "factor"), fDensidad = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("d10", "d20", "d40"), class = "factor")), row.names = c(NA, -27L), class = c("tbl_df", "tbl", "data.frame"))

0 个答案:

没有答案