I have data of this wide format that I want to convert to long format
Cond Construct Line Plant Tube_shoot weight_shoot Tube_root weight_root
1 Standard NA NA 2 199.95 - -
2 Cd0 IIF 43.1 1 3 51.87 4 10.39
3 Cd0 IIF 43.1 2 5 81.80 6 15.05
4 Cd0 IIF 43.1 3 7 101.56 8 16.70
What I basically want is to keep Tube_shoot and weight_shoot together, i.e. treat these two columns as one for melt. But because I can only use
id.vars=c("Cond","Construct","Line","Plant")
the result is not quite what I want.
I have two (ugly) solutions so far:
I melt twice, first by measure.vars=c("Tube_shoot", "Tube_root" ), then by weights, and later remove half of the rows where the result is simply wrong. This is not feasible for me because I have different lengths of data, and I'd always have to check if I'm taking the right rows out.
I paste "tube" with "weight" into a new column, take out the others, melt them, and later take them apart again.
Copy them one by one in excel. But with hundreds of lines I'd rather learn how to do it in R.
I'm sure that there is a better way.
What I want in the end:
Cond Construct Line Plant Tube weight
1 Standard NA NA 2 199.95
2 Cd0 IIF 43.1 1 3 51.87
3 Cd0 IIF 43.1 2 5 81.80
4 Cd0 IIF 43.1 3 7 101.56
2 Cd0 IIF 43.1 1 4 10.39
3 Cd0 IIF 43.1 2 6 15.05
4 Cd0 IIF 43.1 3 8 16.70
You could try
data