I would really appreciate some helpful suggestions for reshaping data in R. I've been looking at related discussions on reshaping between wide and long format with grouped variables, but can't seem to get my data frame to reshape without receiving an error. The data frame looks like this...
mydata
Time GRC1 Height1 GBL2 Height2 GPG3 Height3
1 1899-12-30 10:32:00 Vocal h M m M m
2 1899-12-30 10:42:00 Vocal m M m R m
3 1899-12-30 10:52:00 R m M m OOS NA
4 1899-12-30 11:02:00 M m R m R m
> dput(mydata)
structure(list(Time = structure(c(-2209123680, -2209123080, -2209122480,
-2209121880), class = c("POSIXct", "POSIXt"), tzone = "GMT"),
GRC1 = structure(c(3L, 3L, 2L, 1L), .Label = c("M", "R",
"Vocal"), class = "factor"), Height1 = structure(c(1L, 2L,
2L, 2L), .Label = c("h", "m"), class = "factor"), GBL2 = structure(c(1L,
1L, 1L, 2L), .Label = c("M", "R"), class = "factor"), Height2 = structure(c(1L,
1L, 1L, 1L), .Label = "m", class = "factor"), GPG3 = structure(c(1L,
3L, 2L, 3L), .Label = c("M", "OOS", "R"), class = "factor"),
Height3 = structure(c(1L, 1L, 2L, 1L), .Label = c("m", "NA"
), class = "factor")), .Names = c("Time", "GRC1", "Height1",
"GBL2", "Height2", "GPG3", "Height3"), row.names = c(NA, 4L), class = "data.frame")
I would like the data to look like this...
The only way I can currently manage is to subset mydata into smaller data frames, melt the data, and then rbind everything back together. I feel like there is a better way that I just haven't been able to figure out. Thanks for any suggestions.