Created
August 18, 2014 13:30
-
-
Save bryanyang0528/6a0d2fb1b4261a0f5246 to your computer and use it in GitHub Desktop.
R ddplyr example 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## The code for the toy data is exactly the same | |
data <- data.frame(sex = c(rep(1, 1000), rep(2, 1000)), | |
treatment = rep(c(1, 2), 1000), | |
response1 = rnorm(2000, 0, 1), | |
response2 = rnorm(2000, 0, 1)) | |
## reshape2 still does its thing: | |
library(reshape2) | |
melted <- melt(data, id.vars=c("sex", "treatment")) | |
## This part is new: | |
library(dplyr) | |
grouped <- group_by(melted, sex, treatment) | |
summarise(grouped, mean=mean(value), sd=sd(value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment