为特定列名在R中旋转

为特定列名在R中旋转,r,dataframe,pivot,transpose,R,Dataframe,Pivot,Transpose,我在R Studio中有一个简单的数据框架,我想以它为轴心。我一直在使用'gather()'和'spread()'函数进行更复杂的换位,但我不知道如何做更简单的枢轴 我有以下数据: structure(list(MeanExports = c(1581743294.4, 13114218975.85, 376303283.26, 367309850000, 60019049993.7, 632530400000, 4276027773.125, 3.63436e+11, 1530830933

我在R Studio中有一个简单的数据框架,我想以它为轴心。我一直在使用'gather()'和'spread()'函数进行更复杂的换位,但我不知道如何做更简单的枢轴

我有以下数据:

structure(list(MeanExports = c(1581743294.4, 13114218975.85, 
376303283.26, 367309850000, 60019049993.7, 632530400000, 4276027773.125, 
3.63436e+11, 1530830933.675, 317033050000), Development = c("Less", 
"Less", "Less", "More", "More", "More", "Less", "More", "Less", 
"More")), row.names = c(331L, 2635L, 4363L, 13435L, 16171L, 16747L, 
17323L, 17755L, 18331L, 29563L), class = "data.frame")
我希望能够创建一个新的数据框架,其中包含五行的“较发达”和“较不发达”列(每个类别有五个值)。对于更复杂的程序,网上有很多建议,但我相信会有一个我忽略的简单方法。任何帮助都将是惊人的。

stack()
unstack()
是(经常被忽略的)基本R函数

dfw <- unstack(df)
names(dfw) <- paste(names(dfw), 'Developed')

#   Less Developed More Developed
# 1     1581743294   367309850000
# 2    13114218976    60019049994
# 3      376303283   632530400000
# 4     4276027773   363436000000
# 5     1530830934   317033050000
dfw
df%>%group\u by(Development)%%>%mutate(row=row\u number())%%>%pivot\u wide(names\u from=Development,values\u from=meansexports)