1. Working with output objects
Up to this point in the course, you have run functions and displayed the output in the console. However, it is helpful to save your output to be able to view your results without rerunning the code and to extract only the specific elements of interest.
2. Output from summary
Let's see what the output from the summary function looks like. You can save the output in an object called davissmry.
You will notice that there are 6 rows of formatted output in the davis summary object for each of the three variables. Each row shows the name of the statistic and the value of each statistic.
3. Output from summary
The class of the summary output is a table object which is also a matrix class type. This table object has 6 rows and 3 columns.
4. Select elements from summary object
Since this output is of matrix class, you can use the row and column index selectors inside single brackets. For example, you can display columns 1 to 2 using this syntax.
You can also display rows 4 to 6 which shows the mean, third quartile and maximum statistics.
5. Output from dplyr summarise
Output from the summarise function from dplyr creates a data frame class object. The str structure function not only shows the class of this davissmall object, but also displays the dimensions which are 1 row observation by 4 column variables.
The structure function also displays the names of the elements in the data frame output.
6. Display elements from summarise output
With data frames you can also use the single bracket syntax to select specific rows and columns. You can display column 3 for mean height from the davissmall dataset.
Since, the davissmall object is a data frame, you can also use the dollar sign operator to select the element height_mean to get the same result.
7. Output from dplyr group_by
The dplyr package also provides the helpful group_by function. This creates a custom output class that is special type of data frame called a tibble or tbl.
You'll notice that you still get 3 named elements for each statistic requested in the summarise statement. However, there are now 2 rows, one for each sex group.
8. Display elements from group_by output
Since davisbmisex is a dataframe, the row column index syntax can be used for selecting and displaying elements such as column 2 and row 1.
9. Display elements from group_by output
The dollar sign selector may also be used to display the standard deviation for bmi in the davisbmisex dataframe output. The dplyr filter function can also be used to display only the output row for the male sex group.
10. Output from psych describe
As you saw in chapter 2, the describe function from the psych package gives you many more descriptive statistics than the summary function. You can save the descriptive output shown here as davispsych.
11. Class and structure of psych describe output
The output from psych describe is a data frame that is customized for the psych package, which is why the structure output shows the class type as psych, describe and data frame.
There are 3 rows, one for each of the variables you requested statistics on for weight, height and bmi.
The 13 variables listed here from the str function for the davispsych object are the statistics produced by the psych describe function.
12. Display psych describe output elements
Since davispsych is a data.frame, you can use the dollar sign selector to select and display a specific statistic like the trimmed means for weight, height and bmi.
You can also use the dplyr slice function to selectively display row 2 for the height statistics.
13. Display psych describe output elements
And you can use the dplyr select function to selectively display the columns for sample size n, median, min and max.
14. Let's customize the results for the statistical output on abalones!
Let's get to work customizing the results for the statistical output on abalones!