SHARE
TWEET

Untitled

a guest Jul 16th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top