my data look like this : 1-pre 2-mid 3-post
id<-c(1,2,3,4,5,6,7,8,9)
type<-c(1,2,2,1,2,1,1,1,2) #is the factor level 1 and 2
k1<-c(30.7,20.3,3.4,22,11.6,29.5,15.4,2.7,2.1)
k2<-c(13.4,11,1.4,9.6,17.3,27.1,9.3,5.3,4.7)
k3<-c(1.2,10,4.7,2.6,13.4,14.8,8.8,0.7,4.6)
m1<-c(12 ,12.6, 1.6, 6.2, 10.5, 8.6, 15.3, 1.5, 1.3)
m2<-c(6.6 ,10.5, 0.5, 2.7, 5.2, 8.5, 9.6, 0.6, 4.3)
m3<-c(2,11, 2.6,0.4,7.2,9.4,12.3,0.3,2)
df<-data.frame(type,k1,k2,k3,m1,m2,m3,id)
df[,1]<-as.factor(df[,1])
my new data frame look like this
type id time score
1 1 1 k1 30.7
2 1 1 k2 13.4
3 1 1 k3 1.2
4 1 1 m1 12.0
5 1 1 m2 6.6
6 1 1 m3 2.0
7 2 2 k1 20.3
8 2 2 k2 11.0
this command i use
dflong<-tidyr::gather(df,key=time, value=score, k1:k3,m1:m3)%>% arrange(id)
i want one column for period (pre,mid,post) and other column for value of m and k variable