I have this data which is in wide format, with the width of s02 occupying a maximum of three that is 0,1,2
id_1<-c(1,2,2,2)
s02_0<-c(1,1,4,7)
s02_1<-c(2,2,5,8)
s02_2<-c(3,3,6,9)
id_2<-c(1,1,2,3)
I would wish to reshape my data, and create an extra column say n which shows the position occupied by 's02_' in every given row. My expected output is as below
id_1<-c(1,1,1,2,2,2,2,2,2,2,2,2)
s02<-c(1,2,3,1,2,3,4,5,6,7,8,9)
n<-c(1,2,3,1,2,3,1,2,3,1,2,3)
df2<-data.frame(id_1,s02,n)