I have data in the format:
sample height width weight
1 a h1 w1 p1
2 a h2 w2 p2
3 b h3 w3 p3
4 b h4 w4 p4
where h1 and h2 are replicate measurements for the height of sample "a", h3 and h4 are replicate measurements for sample "b", etc.
I need to put replicate measurements side by side:
sample height1 height2 width1 width2 weight1 weight2
1 a h1 h2 w1 w2 p1 p2
2 b h3 h4 w3 w4 p3 p4
I have been fiddling with gather
and spread
but haven't been able to get what I wanted. Any help please?
Thanks!
data
df1 <- structure(list(sample = c("a", "a", "b", "b"), height = c("h1",
"h2", "h3", "h4"), width = c("w1", "w2", "w3", "w4"), weight = c("p1",
"p2", "p3", "p4")), .Names = c("sample", "height", "width", "weight"
), row.names = c(NA, -4L), class = "data.frame")