I have a dataframe as follows,
id sex age trt.1 response.1 trt.2 response.2
1 1 <NA> NA A 1 B 1
2 2 <NA> NA A 1 B 1
3 3 <NA> NA A 1 B 1
4 4 M 28 A 1 B 1
5 5 F 39 A 1 B 1
6 6 M 47 A 1 B 1
I want to change it to
id sex age times response
1 1 <NA> NA A 1
2 1 <NA> NA B 1
3 2 <NA> NA A 1
4 2 <NA> NA B 1
.
.
.
.
I tried the following,
reshape(merged, idvar = "id", varying = list(4:7), v.names="response", times=c("A","B"), direction="long")
But I am getting this error,
Error in reshapeLong(data, idvar = idvar, timevar = timevar, varying = varying, :
'times' is wrong length
I tried times = C("A","B","A","B") that time I get the output, but the original data frame is 70 rows and the output should be 140 rows, but when I use this I am get 280 rows which is wrong. Can anybody help me where I am doing mistake?