使用R重塑数据框中的行组织

西蒙·贝斯纳德

我有这个数据框。

structure(list(Driver = c("Crop agriculture", "Infrastructure", 
"Mining", "Mixed Agriculture", "Other land use", "Pasture", "Tree crops", 
"Water", "Crop agriculture", "Infrastructure", "Mining", "Mixed Agriculture", 
"Other land use", "Pasture", "Tree crops", "Water", "Crop agriculture", 
"Infrastructure", "Mining", "Mixed Agriculture", "Other land use", 
"Pasture", "Tree crops", "Water", "Crop agriculture", "Infrastructure", 
"Mining", "Mixed Agriculture", "Other land use", "Pasture", "Tree crops", 
"Water"), Period = c("1990-2000", "1990-2000", "1990-2000", "1990-2000", 
"1990-2000", "1990-2000", "1990-2000", "1990-2000", "1990-2000", 
"1990-2000", "1990-2000", "1990-2000", "1990-2000", "1990-2000", 
"1990-2000", "1990-2000", "2000-2005", "2000-2005", "2000-2005", 
"2000-2005", "2000-2005", "2000-2005", "2000-2005", "2000-2005", 
"2000-2005", "2000-2005", "2000-2005", "2000-2005", "2000-2005", 
"2000-2005", "2000-2005", "2000-2005"), Value = c(129536.358373574, 
14089.3660954917, 985.646531415156, 34951.5705930615, 75478.7796771996, 
1001024.77681633, 9673.51414314377, 51631.4446491193, 0.0983294102032751, 
0.0106950594852475, 0.000748191807457263, 0.0265312948831128, 
0.057294986378404, 0.759865238911138, 0.0073430421561273, 0.0391927761752383, 
273356.204972389, 12040.5899468613, 607.505228212054, 45165.8223684273, 
75748.9976185639, 1221137.74328547, 8851.85933777376, 39629.016246337, 
0.163048047540391, 0.00718181861746466, 0.000362357025480948, 
0.0269399377763239, 0.0451818028644936, 0.728368777437064, 0.00527984496372407, 
0.0236374137750571), n = c("n = 1669", "n = 298", "n = 20", "n = 1355", 
"n = 1623", "n = 10986", "n = 316", "n = 466", "n = 1669", "n = 298", 
"n = 20", "n = 1355", "n = 1623", "n = 10986", "n = 316", "n = 466", 
"n = 783", "n = 151", "n = 7", "n = 925", "n = 851", "n = 6039", 
"n = 211", "n = 244", "n = 783", "n = 151", "n = 7", "n = 925", 
"n = 851", "n = 6039", "n = 211", "n = 244"), Type = c("Sum", 
"Sum", "Sum", "Sum", "Sum", "Sum", "Sum", "Sum", "Percentage", 
"Percentage", "Percentage", "Percentage", "Percentage", "Percentage", 
"Percentage", "Percentage", "Sum", "Sum", "Sum", "Sum", "Sum", 
"Sum", "Sum", "Sum", "Percentage", "Percentage", "Percentage", 
"Percentage", "Percentage", "Percentage", "Percentage", "Percentage"
)), .Names = c("Driver", "Period", "Value", "n", "Type"), row.names = c("1", 
"3", "5", "7", "9", "11", "13", "15", "12", "31", "51", "71", 
"91", "111", "131", "151", "2", "4", "6", "8", "10", "122", "14", 
"16", "21", "41", "61", "81", "101", "121", "141", "161"), class = "data.frame")

我想根据两个条件重新组织此数据框。首先,我想在前8行中包含Sum对象,然后是百分比。然后,我也想将相同的驱动程序类耦合在一起。简而言之,例如,我想拥有Crop agriculture1990-2000年,紧随其后Crop agriculture的是2000-2005年,依此类推。谢谢你的帮助。

西蒙·贝斯纳德

这是答案

C_Em_df<-ddply(C_Em_df, .(Type, Driver))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章