How to get the summary of data from a data frame in R
Overview
A data frame in R represents the data displayed in a table format. Like a table with columns and rows, a data frame can contain different data types inside it.
How to create a data frame
In R, we use the data.frame() function to create a data frame.
Example
# creating a data frameMy_Data_Frame <- data.frame (Height = c("Tall", "Average", "short"),Body_structure = c("Meso", "Endo", "Ecto"),Age = c(35, 30, 45))# Print the data frameMy_Data_Frame
Explanation
- Line 2: We use the
data.frame()function to create a data frame variableMy_Data_frame. This data frame contains three columns. - Line 9: We print the data frame.
How to summarize data from a data frame
We use the summary() function to summarize the data from a data frame.
Syntax
summary(data frame)
Parameter value
This function takes the data frame object as its single parameter value.
Return value
This function returns a summary (statistical inference) of the data frame.
Example
# creating a data frameMy_Data_frame <- data.frame (Height = c("Tall", "Average", "Short", "Tall"),Body_structure = c("Meso", "Endo", "Ecto", "Endo"),Age = c(35, 30, 45, 25))# Print the data frameMy_Data_frame# Summarizing the datasummary(My_Data_frame)
Explanation
This is similar to the previous example, except we use the summary() function to summarize the data frame My_Data_frame. This can be observed from the output of the code.