How to use Summary Function in R?

In this article, we will discuss the Summary Function in R Programming Language.

Summary function is used to return the following from the given data.

Syntax:

summary(data)

Where, data can be a vector, dataframe, etc.

Example 1: Using summary() with Vector

Here we are going to create a vector with some elements and get the summary statistics.

R

# create a vector with 10 elements data = c (1: 5, 56, 43, 56, 78, 51) print (data) # get summary print ( summary (data))

Output:

Example 2: Using summary() with DataFrame

Here we are going to get the summary of all columns in the dataframe.

R

# create a dataframe with 3 columns data = data.frame (col1= c (1: 5, 56, 43, 56, 78, 51), col2= c (100: 104, 56, 43, 56, 78, 51), col3= c (1: 5, 34, 56, 78, 76, 79)) print (data) # get summary print ( summary (data))

Output:

Example 3: Using summary() with Specific DataFrame Columns

Here we can get summary of particular columns of the dataframe.

Syntax:

summary(dataframe)

R

# create a dataframe with 3 columns data = data.frame (col1= c (1: 5, 56, 43, 56, 78, 51), col2= c (100: 104, 56, 43, 56, 78, 51), col3= c (1: 5, 34, 56, 78, 76, 79)) print (data) # get summary of column 1 and column 3 print ( summary (data[ c ( 'col1' , 'col3' )]))

Output:

Example 4: Using summary() with Regression Model

Here we can also calculate summary() for linear regression model. We can create an linear regression model for dataframe columns using lm() function.

Syntax:

summary(lm(column1~column2, dataframe))

R

# create a dataframe with 3 columns data = data.frame (col1= c (1: 5, 56, 43, 56, 78, 51), col2= c (100: 104, 56, 43, 56, 78, 51)) # create the model for regression with 2 columns reg = lm (col1~col2, data) # get summary of the model summary (reg)

Output:

Example 5: Using summary() with ANOVA Model

Here aov() is used to create anova model which stands for analysis of variance.

Syntax:

summary(aov(col1 ~ col2, data))

Example:

R

# create a dataframe with 3 columns data = data.frame (col1= c (1: 5, 56, 43, 56, 78, 51), col2= c (100: 104, 56, 43, 56, 78, 51)) # create the model for anova model with 2 columns reg = aov (col1 ~ col2, data) # get summary of the model summary (reg)

Output:

Like Article -->

Please Login to comment.

Similar Reads

Get Summary of Results produced by Functions in R Programming - summary() Function

summary() function in R Language is a generic function used to produce result summaries of the results of various model fitting functions. Syntax: summary(object, maxsum) Parameters: object: R object maxsum: integer value which indicates how many levels should be shown for factors Example 1: # R program to illustrate # summary function # Initializi

2 min read Compute Summary Statistics of Subsets in R Programming - aggregate() function

In R programming, aggregate() function is used to compute the summary statistics of the split data. It takes the data frame or time series analysis object. Syntax: aggregate(x, by, FUN) Parameters: x: specifies R object by: specifies list of grouping elements FUN: specifies function to compute the statistical summary To know about more optional par

2 min read Tukey's Five-number Summary in R Programming - fivenum() function

fivenum() function in R Language is used to return Tukey's five-number summary of input data i.e., minimum value, lower-hinge value, median value, upper-hinge value and maximum value of the input data. Syntax: fivenum(x, na.rm = TRUE) Parameters: x: indicates numeric object na.rm: indicates logical value. If TRUE, NAs and NANs are dropped. Example

1 min read How to Calculate Five Number Summary in R?

In this article, we will discuss how to calculate five number summary in R programming language. Five number summary is also known as a boxplot. it will return five values that are : The minimum value present in the given dataThe first quartile value present in the given dataThe median value present in the given dataThe third quartile value present

2 min read How to find group-wise summary statistics for R dataframe?

Finding group-wise summary statistics for the dataframe is very useful in understanding our data frame. The summary includes statistical data: mean, median, min, max, and quartiles of the given dataframe. The summary can be computed on a single column or variable, or the entire dataframe. In this article, we are going to see how to find group-wise

4 min read Get the summary of dataset in R using Dply

In this article, we will discuss how to get a summary of the dataset in the R programming language using Dplyr package. To get the summary of a dataset summarize() function of this module is used. This function basically gives the summary based on some required action for a group or ungrouped data, which in turn helps summarize the dataset. Syntax:

2 min read How to get summary statistics by group in R

In this article, we will learn how to get summary statistics by the group in R programming language. Sample dataframe in use: grpBy num 1 A 20 2 A 30 3 A 40 4 B 50 5 B 50 6 C 70 7 C 80 8 C 25 9 C 35 10 D 45 11 E 55 12 E 65 13 E 75 14 E 85 15 E 95 16 E 105Method 1: Using tapply() tapply() function in R Language is used to apply a function over a sub

6 min read How to Create Summary Tables in R?

In this article, we will discuss how to create summary tables in R Programming Language. The summary table contains the following information: vars: represents the column numbern: represents the number of valid casesmean: represents the mean valuemedian: represents the median valuetrimmed: represents the trimmed meanmad: represents the median absol

4 min read How to Calculate Summary Statistics by Group in R?

In this article, we will discuss how to calculate summary statistics by the group in the R programming language. What is summary statistics in R?Summary Statistics by Group in R Programming Language are numerical or graphical representations that provide a concise and informative overview of a dataset. They help you understand the central tendencie

5 min read Compute Summary Statistics In R

Summary statistics provide a concise overview of the characteristics of a dataset, offering insights into its central tendency, dispersion, and distribution. R Programming Language with its variety of packages, offers several methods to compute summary statistics efficiently. Here we'll explore various techniques to compute summary statistics in R.

4 min read Check if a Function is a Primitive Function in R Programming - is.primitive() Function

is.primitive() function in R Language is used to check if a function is a primitive function, i.e. its either a built-in function or a special function. Syntax: is.primitive(func) Parameters: func: Function to be checked Example 1: # R program to illustrate # the use of is.primitive function # Calling is.primitive() function is.primitive(1) is.prim

1 min read How to Use the replicate() Function in R?

replicate() function in R Programming Language is used to evaluate an expression N number of times repeatedly. Syntax: replicate(n, expression) where expression is a statement to evaluaten is the number of times to evaluate the expressionMethod 1: Replicate a value n times Here we will replicate some values n times. Example: C/C++ Code # replicate

1 min read How to Use Dist Function in R?

In this article, we will see how to use dist() function in R programming language. R provides an inbuilt dist() function using which we can calculate six different kinds of distances between each unique pair of vectors in a two-dimensional vector. dist() method accepts a numeric matrix as an argument and a method that represent the type of distance

11 min read How to Use ColMeans Function in R?

In this article, we will discuss how to use the ColMeans function in R Programming Language. Using colmeans() function The colmean() function call be simply called by passing the parameter as the data frame to get the mean of every column present in the data frame separately in the R language. Syntax: colMeans(dataframe) where dataframe is the inpu

3 min read How to Use sum Function in R?

In this article, we will discuss how to use the sum() function in the R Programming Language. sum() function: This is used to return the total/sum of the given data Syntax: sum(data) Arguments: data can be a vector or a dataframeExample 1: Using sum() function to calculate the sum of vector elements In this method, the user has to simply call the s

5 min read How to Use aggregate Function in R

In this article, we will discuss how to use aggregate function in R Programming Language. aggregate() function is used to get the summary statistics of the data by group. The statistics include mean, min, sum. max etc. Syntax: aggregate(dataframe$aggregate_column, list(dataframe$group_column), FUN) where dataframe is the input dataframe.aggregate_c

2 min read How to Use Par Function in R?

In this article, we will discuss how to use the par() function in the R Programming Language. The par() function is used to set or query graphical parameters. We can divide the frame into the desired grid, add a margin to the plot or change the background color of the frame by using the par() function. We can use the par() function in R to create m

4 min read How to Use Nrow Function in R?

In this article, we will discuss how to use Nrow function in R Programming Language. This function is used in the dataframe or the matrix to get the number of rows. Syntax: nrow(data) where, data can be a dataframe or a matrix. Example 1: Count Rows in Data Frame In this example, we are going to count the number of rows in the dataframe. C/C++ Code

2 min read How to Use lm() Function in R to Fit Linear Models?

In this article, we will learn how to use the lm() function to fit linear models in the R Programming Language. A linear model is used to predict the value of an unknown variable based on independent variables. It is mostly used for finding out the relationship between variables and forecasting. The lm() function is used to fit linear models to dat

4 min read How to Use the Jitter Function in R for Scatterplots?

In this article, we will discuss how to use the jitter function in the R programming Language for Scatterplots. Scatterplots is a visualization plot that uses cartesian coordinates to display values for typically two variables for a set of data by having them at the x-axis and the y-axis. This is very helpful in understanding the relationship betwe

3 min read How to use the source Function in R

In this article, we will be looking at the practical implementation of the source function in the R programming language. Source Function: Source function in R is used to use functions that are created in another R script. The syntax of this function is given below: source("Users/harsh/Desktop/GeeksforGeeks/gfg.R") All we are required is to put the

2 min read How to Use colMax Function in R

As we know in R, while base functions like colMeans and colSums exist to calculate column-wise means and sum in a data frame, there isn't a built-in colMax function for finding the maximum value in each column. So the question arises of how to use the colMax function in R Programming Language. How to Use the colMax Function in R?The colMax function

4 min read How to Use the coeftest() Function in R

In R Programming language, we use coeftest() function to perform hypothesis tests and construct confidence intervals for regression coefficients. It is used after fitting regression models using functions like lm() (for linear regression), glm() (for generalized linear models), or any other function that returns a suitable object with coefficient e

5 min read How to Use the linearHypothesis() Function in R

In statistics, understanding how variables relate to each other is crucial. This helps in making smart decisions. When we build regression models, we need to check if certain combinations of variables are statistically significant. In R Programming Language a tool called linear hypothesis () in the "car" package for this purpose. Also, this article

4 min read How to Use file.path() Function in R

R programming language is becoming popular among developers, analysts, and mainly for data scientists. Students are eagerly learning R with Python language to use their analytical skills at their best. While learning any language, one is faced with many difficulties, and the individual learning R Programming Language gets stuck in finding solutions

3 min read How to Use Gather Function in R

In data analysis and manipulation, it's often necessary to reshape datasets for better comprehension or analysis. The gather() function in the R Programming Language part of the tidyr package, is a powerful tool for reshaping data from wide to long format. This article will explore the gather() function in detail, providing explanations and example

4 min read How to Use Map Function with the Base R Pipe |>

The R Programming Language, widely used for statistical computing and data analysis, has continued to evolve to make coding more efficient and intuitive. One significant advancement in recent versions of R is the introduction of the native pipe operator |>, which allows for a cleaner and more readable way to chain functions. This article explore

4 min read How to Use the tryCatch() Function in R?

In R Programming Language handling errors and exceptions gracefully is crucial to ensure robust and error-free code. The tryCatch() function in R is a powerful tool for this purpose. This function allows you to catch and handle errors, warnings, and messages in a controlled manner. In this article, we will explore how to use the try-catch () functi

6 min read How to Use the drop() Function in R

In R Language the drop() function is used to eliminate redundant dimensions of an object, such as dropping dimensions from a matrix, data frame, or array. The function simplifies the structure by reducing the number of dimensions when the result has only one row one column, or both. This can be particularly useful when working with subsets of matri

3 min read Compute Density of the Distribution Function in R Programming - dunif() Function

dunif() function in R Language is used to provide the density of the distribution function. Syntax: dunif(x, min = 0, max = 1, log = FALSE) Parameters: x: represents vector min, max: represents lower and upper limits of the distribution log: represents logical value for probabilities Example 1: # Create vector of random deviation u <- runif(20)