Skip to content

Data Science Tutorials

For Data Science Learners

  • How to Standardize Data in R
    How to Standardize Data in R? R
  • Anderson-Darling Test in R With Examples
    Anderson-Darling Test in R With Examples R
  • The Ultimate Guide to Becoming a Data Analyst
    The Ultimate Guide to Becoming a Data Analyst: A Step-by-Step Process Machine Learning
  • Dynamic data visualizations in R
    Dynamic data visualizations in R R
  • How to perform MANOVA test in R
    How to perform the MANOVA test in R? R
  • How to Use Gather Function in R
    How to Use Gather Function in R?-tidyr Part2 R
  • How to Check if a Directory Exists in R
    How to Check if a Directory Exists in R R
  • Best AI and Machine Learning Courses
    Best AI and Machine Learning Courses Machine Learning
How to create summary table in R

How to create summary table in R

Posted on December 19December 19 By Admin No Comments on How to create summary table in R

How to create summary table in R, Using the describe() and describeBy() methods from the psych library is the most straightforward method for creating summary tables in R.

How to create summary table in R

To create summary tables in R using the `psych` library, you can follow these steps:

1. Basic Summary Table:

library(psych)
df <- data.frame(team=c('A', 'A', 'B', 'B', 'C', 'C', 'C'),
                 points=c(15, 22, 29, 41, 30, 11, 19),
                 rebounds=c(17, 28, 36, 36, 7, 19, 13),
                 steals=c(1, 1, 2, 3, 5, 7, 5))
df

Let’s create summary table

ggplot2 colors in R-Default colors complete guide » finnstats

describe(df)

          vars n  mean    sd median trimmed   mad min max range  skew kurtosis se
team*       1 7  2.14  0.90      2    2.14  1.48   1   3     2 -0.22    -1.90 0.34
points      2 7 23.86 10.24     22   23.86 10.38  11  41    30  0.33    -1.41 3.87
rebounds    3 7 22.29 11.31     19   22.29 13.34   7  36    29  0.08    -1.82 4.27
steals      4 7  3.43  2.30      3    3.43  2.97   1   7     6  0.25    -1.73 0.87

In the first example, we load the `psych` library and then use the `describe()` function to create a summary table for each variable in the data frame. We can view the output using the `view()` function.

2. Summary Table, Grouped by Specific Variable:

The code below demonstrates how to arrange the data frame by the “team” variable to produce a summary table using the describeBy() function:

library(psych)

Let’s create summary table, grouped by ‘team’ variable

describeBy(df, group=df$team, fast=TRUE)

Descriptive statistics by group 
group: A
         vars n mean   sd min max range  se
team*       1 2  1.0 0.00   1   1     0 0.0
points      2 2 18.5 4.95  15  22     7 3.5
rebounds    3 2 22.5 7.78  17  28    11 5.5
steals      4 2  1.0 0.00   1   1     0 0.0
---------------------------------------------------------------------------------- 
group: B
         vars n mean   sd min max range  se
team*       1 2  2.0 0.00   2   2     0 0.0
points      2 2 35.0 8.49  29  41    12 6.0
rebounds    3 2 36.0 0.00  36  36     0 0.0
steals      4 2  2.5 0.71   2   3     1 0.5
---------------------------------------------------------------------------------- 
group: C
         vars n  mean   sd min max range   se
team*       1 3  3.00 0.00   3   3     0 0.00
points      2 3 20.00 9.54  11  30    19 5.51
rebounds    3 3 13.00 6.00   7  19    12 3.46
steals      4 3  5.67 1.15   5   7     2 0.67

In the second example, we load the `psych` library and then use the `describeBy()` function to create a summary table for each variable in the data frame, grouped by a specific variable (in this case, ‘team’).

We set the `fast=TRUE` argument to only calculate the most common summary statistics. After creating the summary table, we can view it using the `view()` function.

The output will show descriptive statistics for each group (in this case, A, B, C).

How to copy files in R » Data Science Tutorials

R

Post navigation

Previous Post: How to copy files in R
Next Post: Stacked Barplot in R

Related Posts

  • How to Standardize Data in R
    How to Standardize Data in R? R
  • Select the First Row by Group in R
    Select the First Row by Group in R R
  • How to copy files in R
    How to copy files in R R
  • Two Sample Proportions test in R
    Two Sample Proportions test in R-Complete Guide R
  • R Percentage by Group Calculation
    R Percentage by Group Calculation R
  • How to Create an Interaction Plot in R
    How to Create an Interaction Plot in R? R

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Best Prompt Engineering Books
  • Understanding Machine Learning and Data Science
  • Best Git Books
  • Top 5 Books to Learn Data Engineering
  • Mastering R Programming for Data Science: Tips and Tricks
  • About Us
  • Contact
  • Disclaimer
  • Privacy Policy

https://www.r-bloggers.com

  • YouTube
  • Twitter
  • Facebook
  • Course
  • Excel
  • Machine Learning
  • Opensesame
  • R
  • Statistics

Check your inbox or spam folder to confirm your subscription.

  • Subsetting with multiple conditions in R
    Subsetting with multiple conditions in R R
  • Normal distribution in R
    Normal Distribution in R R
  • ggpairs in R
    ggpairs in R R
  • Convert Multiple Columns to Numeric in R
    Convert Multiple Columns to Numeric in R R
  • best books about data analytics
    Best Books to learn Tensorflow Course
  • How to Turn Off Scientific Notation in R
    How to Turn Off Scientific Notation in R? R
  • Tips for Rearranging Columns in R
    Tips for Rearranging Columns in R R
  • How to Use Italic Font in R
    How to Use Italic Font in R R

Privacy Policy

Copyright © 2025 Data Science Tutorials.

Powered by PressBook News WordPress theme