我想将第一列的行移动到列,将第二列的值移动到行
###### CREATE THE DATA FRAME ######
Hypothesis <- c("Hyp_1", "Hyp_2", "Hyp_3")
Estimates <- c(0.34, 0.01, 0.22)
df <- as.data.frame(cbind(Hypothesis, Estimates))
df
Hypothesis Estimates
Hyp_1 0.34
Hyp_2 0.01
Hyp_3 0.22
我想要的是下一个格式
Hyp_1 Hyp_2 Hyp_3
0.34 0.01 0.22
谢谢!!!!
我尝试了下一个代码但没有成功
dcast(df, Estimates~Hypothesis)
试试这个:
library(tidyverse)
pivot_wider(df, names_from = Hypothesis, values_from = Estimates)