Using R how do I pivot the columns into rows to get the required structure in df3 from df2, while extracting new information from the previous dataframe:
df2<- structure(list(A=c("A_1_01", "A_1_01", "A_1_01"), B=c("A", "A", "A"), C=c("1", "1", "1"), D=c("inside", "eating", "sleeping"), "1"=c("1","1","0"), "2"=c("1","0","0"), "3"=c("0","0","1"), "4"=c("0","1","1"), "1_Location"=c("I","I", "I"), "2_Location"=c("I","I", "I"), "3_Location"=c("O","O", "O"), "4_Location"=c("O","O", "O")), class= "data.frame", row.names = c(NA,-3L))
df3<- structure(list(H=c("1","2","3","4","1","2","3","4","1","2","3","4"),
A=c("A_1_01", "A_1_01", "A_1_01","A_1_01", "A_1_01",
"A_1_01","A_1_01", "A_1_01", "A_1_01","A_1_01",
"A_1_01", "A_1_01"),
B=c("A", "A", "A","A", "A", "A","A", "A", "A","A", "A", "A"),
C=c("1", "1", "1","1", "1", "1","1", "1", "1","1", "1", "1"),
D=c("inside","inside","inside","inside",
"eating","eating","eating","eating",
"sleeping","sleeping","sleeping","sleeping"),
Value=c(1,1,0,0,1,0,0,1,0,0,1,1),
Location=c("I","I","O","O","I","I","O","O","I","I","O","O")),
class= "data.frame", row.names = c(NA,-12L))
Thank you