
The dplyr functions have allowed us to quickly arrive at this snapshot view so that we can proceed to ask more detailed questions of the data if we want to. Needless to say, this is only a glance, not a rigorous analysis. groupby() adds extra structure to your dataset grouping information which lays the groundwork for computations within the groups. This quick exploratory glance indicates that the “family treatment” group exhibited an average weight gain that was significantly higher than that of the control group, whereas the “cognitive behavioral treatment” group appears not to have done so. This is easiest if I use the “ARX” object created earlier. It’s also fine to forego creating any new objects at all if the only thing you want to do is take an exploratory look at some different subsets in the console. I began by storing a lot of data in new objects one “verb” at a time, but that was only for illustration. The nice thing about dplyr is the way it allows a fairly seamless and intuitive method of defining that path without making you create a bunch of new variables.

#DPLYR SUMMARIZE FULL#
Here is the full path to the final result we saw above, moving from the original data frame to the summary table in one statement. I will go ahead and store that last set of commands in an object: ARXwtdeltaTable %

WtChangeStDev = sd(wtDelta)) # Source: local data frame Note that you can use the “summarise” spelling as well dplyr will tolerate either spelling. Then I will use the summarize() verb upon that object. I’ll store that last set of manipulations in an object: ARXwtgrp %

anor1 0)ĪRXneg %”) as being equivalent to saying “then,” as in command1, THEN command2, THEN command3, etc: ARX %>%Īrrange(wtDelta) # Source: local data frame The groups are labeled “Cont,” for the control group, “CBT,” for the group receiving cognitive behavioral treatment, and “FT,” for the group receiving family treatment. For example, we could create new objects to hold subsets for each treatment group. We can use dplyr’s “data manipulation verbs” one at a time to make individual alterations to the data. Start by loading the packages and data: library(MASS) The R MASS package contains a data frame, anorexia, containing “weight change data for young female anorexia patients.” I will use the dplyr package to manipulate this data frame in a few way, concluding with a table summarizing the changes in weight for each treatment group.
