Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. library(reshape2)
  2. library(tidyr)
  3.  
  4. # example data frame
  5. x = data.frame(
  6. id = c(1, 1, 2, 2),
  7. time = c(1, 2, 3, 4),
  8. SBP = c(1, 0, 1, 0),
  9. HR = c(0, 1, 0, 1)
  10. )
  11.  
  12. # collapse the data frame
  13. x_melt <- melt(data = x, id.vars = "id", measure.vars = c("SBP", "HR"))
  14.  
  15.  
  16. # solution using gather from tidyr
  17. x_long <- gather(x, "id", "value", 3:4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement