如何重新设置有关列2:7(day_rep)的多个信息的数据帧,使用coumns获取这个新的“datlong”数据帧: “trat”“day”“rep”“value”
dat <- read.table(header=T, text='
trat 5_1 5_2 6_1 6_2 7_1 7_2
control 0 0 0 0 12 66
control 0 0 0 0 14 76
control 0 0 0 0 18 78
control 0 0 0 0 16 74
control 0 0 0 0 20 76
urea 0 0 0 12 42 88
urea 0 0 0 8 34 76
urea 0 0 0 6 28 68
urea 0 0 0 4 40 60
urea 0 0 0 10 46 78
')
答案 0 :(得分:2)
我们可以使用gather/separate
tidyr
library(dplyr)
library(tidyr)
gather(dat, dayrep, value, -trat) %>%
separate(dayrep, into=c("day", "rep")) %>%
head()
# trat day rep value
#1 control 5 1 0
#2 control 5 1 0
#3 control 5 1 0
#4 control 5 1 0
#5 control 5 1 0
#6 urea 5 1 0