Created
October 5, 2016 18:58
-
-
Save rmflight/839ea9429c578a286c47682ef0c89d39 to your computer and use it in GitHub Desktop.
tidy colMeans
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
| data <- tbl_df(data.frame(values = rnorm(100), id = rep(c("a", "b"), 50))) | |
| data | |
| group_by(data, id) %>% summarise(mean = mean(values)) |
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
| > data <- tbl_df(data.frame(values = rnorm(100), id = rep(c("a", "b"), 50))) | |
| > data | |
| # A tibble: 100 × 2 | |
| values id | |
| <dbl> <fctr> | |
| 1 -0.006761537 a | |
| 2 0.252618198 b | |
| 3 0.018646478 a | |
| 4 0.318055669 b | |
| 5 -0.767953103 a | |
| 6 -0.028615165 b | |
| 7 0.774598954 a | |
| 8 0.970533859 b | |
| 9 -0.915852891 a | |
| 10 0.603263508 b | |
| # ... with 90 more rows | |
| > | |
| > group_by(data, id) %>% summarise(mean = mean(values)) | |
| # A tibble: 2 × 2 | |
| id mean | |
| <fctr> <dbl> | |
| 1 a 0.25660869 | |
| 2 b -0.04340715 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment