Created
July 24, 2014 14:17
-
-
Save bfoste01/77fe11b2e095b1f67a23 to your computer and use it in GitHub Desktop.
This file contains 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
#Fun stuff with plyr | |
#------------------- | |
#plyr .data, .variables to split on and .fun function applied | |
#understand the naming conventions of plyr with the first 2 letters | |
#e.g., ddply dd= split dataframe apply function out dataframe | |
#e.g., dlply dl = split dataframe apply function out list | |
#d = dataframe | |
#l = list | |
#a = array | |
#------------------- | |
#Groupwise Summaries | |
colnames(mtcars) | |
#[1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb" | |
library(plyr) | |
#highest mpg for cylinder type | |
ddply(mtcars, .(cyl), subset, mpg == max(mpg)) | |
#selcect out the highest 25% of mpg per cylinder | |
ddply(mtcars, .(cyl), subset, mpg > quantile(mpg, .75)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment