Get the statistical summary and nature of the DataFrame in R

07 Apr, 2021
In this article, we will see how to find the statistics of the given data frame. We will use the summary() function to get the statistics for each column:
Syntax: summary(dataframe_name)
The result produced will contain the following details:
Minimum value – returns the minimum value from each column
Maximum value – returns the maximum value from each column
Mean – returns the mean value from each column
Median – returns the median from each column
1st quartile – returns the 1st quartile from each column
3rd quartile – returns the 3rd quartile from each column.
Example 1: In this example data, we had taken student marks, height, weight, and marks, so we are calculating the summary of that two columns.
R
# create vector with namesname = c("sravan", "mohan", "sudheer",          "radha", "vani", "mohan")  # create vector with subjectssubjects = c(".net", "Python", "java",             "dbms", "os", "dbms")  # create a vector with marksmarks = c(98, 97, 89, 90, 87, 90)  # create vector with heightheight = c(5.97, 6.11, 5.89, 5.45, 5.78, 6.0)  # create vector with weightweight = c(67, 65, 78, 65, 81, 76)  # pass these vectors to the data framedata = data.frame(name, subjects,                  marks, height, weight)  # displayprint(data)print("STATISTICAL SUMMARY")  # use summary function print(summary(data))
Output:
Example 2: In this example, we are getting a statistical summary of individual columns
R
# create vector with namesname = c("sravan","mohan","sudheer",         "radha","vani","mohan")  # create vector with subjectssubjects = c(".net","Python","java",             "dbms","os","dbms")  # create a vector with marksmarks=c(98,97,89,90,87,90)  # create vector with heightheight=c(5.97,6.11,5.89,         5.45,5.78,6.0)  # create vector with weightweight=c(67,65,78,65,81,76)  # pass these vectors to the data framedata=data.frame(name,subjects,marks,                height,weight)  # displayprint(data)print("STATISTICAL SUMMARY of marks")  # use summary function  on marks columnprint(summary(data$marks))print("STATISTICAL SUMMARY of height")    # use summary function on height columnprint(summary(data$height))print("STATISTICAL SUMMARY of weight")  # use summary function on weight columnprint(summary(data$weight))
Output:
We can use class() function to get the nature of the dataframe.
It will return:
Either data is NULL or not
The datatype of a particular column in a dataframe
Syntax: class(dataframe$column_name)
Example:
R
# create vector with namesname = c("sravan","mohan","sudheer",         "radha","vani","mohan")  # create vector with subjectssubjects = c(".net","Python","java",             "dbms","os","dbms")  # create a vector with marksmarks=c(98,97,89,90,87,90)  # create vector with heightheight=c(5.97,6.11,5.89,         5.45,5.78,6.0)  # create vector with weightweight=c(67,65,78,65,81,76)  # pass these vectors to the data framedata=data.frame(name,subjects,marks,                height,weight)  # nature of dataframeprint(paste("names column",class(data$names)))print(paste("subjects column",class(data$subjects)))print(paste("marks column",class(data$marks)))print(paste("height column",class(data$height)))print(paste("weight column",class(data$weight)))
Output:
Picked
R DataFrame-Programs
R-DataFrame
R Language
R Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Change Color of Bars in Barchart using ggplot2 in R
How to Split Column Into Multiple Columns in R DataFrame?
Group by function in R using Dplyr
How to Change Axis Scales in R Plots?
How to filter R DataFrame by values in a column?
How to Split Column Into Multiple Columns in R DataFrame?
How to filter R DataFrame by values in a column?
Replace Specific Characters in String in R
Merge DataFrames by Column Names in R
How to Sort a DataFrame in R ?