Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(dyplr)
- library(reshape2)
- # Convert a dataframe in long format to wide format when we have more than 1 IV factor
- # Original data frame "df" in long format
- # We have one dependent variable (dv) and two independent variables (iv1, iv2)
- # as separate columns.
- df_group_summary <- df %>%
- group_by(id, iv1, iv2) %>%
- summarise(mean(dv))
- #Reshape
- wide_group_summary <- dcast(df_group_summary, id ~ iv1 + iv2)
- write_csv(wide_group_summary, "/path/wide_group_summary.csv")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement