Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. library(dyplr)
  2. library(reshape2)
  3.  
  4. # Convert a dataframe in long format to wide format when we have more than 1 IV factor
  5.  
  6. # Original data frame "df" in long format
  7. # We have one dependent variable (dv) and two independent variables (iv1, iv2)
  8. # as separate columns.
  9.  
  10. df_group_summary <- df %>%
  11. group_by(id, iv1, iv2) %>%
  12. summarise(mean(dv))
  13.  
  14. #Reshape
  15. wide_group_summary <- dcast(df_group_summary, id ~ iv1 + iv2)
  16. write_csv(wide_group_summary, "/path/wide_group_summary.csv")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement