【发布时间】:2021-04-29 16:40:15
【问题描述】:
我想将宽格式数据(样本名称放在列名中)转换为长格式(其中为该样本名称添加了一个列)。
查看示例:
df <-data.frame(Assay=c("alpha","beta","theta"),
One_mean =c(3,4,5),
Two_mean =c(6,7,8),
Three_mean =c(8,8,8),
One_plus =c(1.3,1.4,1.5),
Two_plus =c(1.6,1.7,1.8),
Three_plus =c(1.8,1.8,1.8),
One_minus =c(.3,.4,.5),
Two_minus =c(.6,.7,.8),
Three_minus =c(.8,.8,.8))
输出:
output_df <- data.frame(Assay=c("alpha","beta","theta",
"alpha","beta","theta",
"alpha","beta","theta"),
Sample= c("One", "Two", "Three",
"One", "Two", "Three",
"One", "Two", "Three"),
mean = c(3,4,5,
6,7,8,
8,8,8),
plus = c(1.3,1.4,1.5,
1.6,1.7,1.8,
1.8,1.8,1.8),
minus = c(.3,.4,.5,
.6,.7,.8,
.8,.8,.8))
谢谢!
【问题讨论】:
标签: r