给定tbl_df
对象df
包含多个变量(即Var.50,Var.100,Var.150和Var.200),测量两次(即P1和P2),我想mutate
一组新的相同变量重复测量(例如,平均P1和P2,为每个相应的变量创建P3)。如何使用dplyr来变更多个变量?
Similar questions之前已经问过,但似乎没有有clear answers using dplyr
.
示例数据:
df <- structure(list(P1.Var.50 = c(134.242050170898, 52.375, 177.126017252604
), P1.Var.100 = c(395.202219645182, 161.636606852214, 538.408426920573
), P1.Var.150 = c(544.40028889974, 266.439168294271, 718.998555501302
), P1.Var.200 = c(620.076151529948, 333.218780517578, 837.109700520833
), P2.Var.50 = c(106.133892059326, 113.252154032389, 172.384114583333
), P2.Var.100 = c(355.226725260417, 277.197153727214, 502.086781819661
), P2.Var.150 = c(481.993103027344, 329.575764973958, 709.315409342448
), P2.Var.200 = c(541.859161376953, 372.05473836263, 829.299621582031
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-3L), .Names = c("P1.Var.50", "P1.Var.100", "P1.Var.150", "P1.Var.200",
"P2.Var.50", "P2.Var.100", "P2.Var.150", "P2.Var.200"))
也许熔融数据集,然后在2份分割可变柱,对P个变量dcast,创建P3,重熔,CONCAT列,redcast –