How to use summarise method In R Language

The summarise method is used to create a summary of the values across the data rows that fall within one column. It is preferably used with a group_by method and the output data contains one row for each of the groups present in the column for which the group_by method is invoked. The method has the following syntax:

Syntax : Summarise(new-col-name=fun())

Arguments: fun – any aggregate function that may be applied over the rows

In the following code snippet, a new column sum is displayed which contains the submission of the values present in the col1 and col3 values of the data. The sum aggregate method has been used to calculate the total values.

R




# Computing the mean 
data %>% 
  rowwise() %>% 
  summarise(sum = sum(c(col1,col3)))


Output:

 

Row wise operation in R using Dplyr

The dplyr package in R programming is used to perform simulations in the data by performing manipulations and transformations. It can be installed into the working space using the following command :

install.packages("dplyr")

Similar Reads

Create Dataframe using Row

The data frame created by tibble contains rows and columns arranged in a tabular structure. It illustrates the data type of the data frame’s column. It can be created in R using the following dimensions...

Application of the mutate method

...

Using a combination of rowwise() and mutate() methods

The mutate() method in R is then applied using the pipe operator to create new columns in the provided data. The mutate() method is used to calculate the aggregated function provided....

Using summarise method

...

Using summarise in combination with group_by

In the following code snippet, the rowwise method is used in collaboration with the mutate method. Therefore the mean value of col1 and col3 value of the data table is calculated for each row individually. For instance, the mean of 1 and 3 in row 1 of the table is equivalent to 2 and is therefore displayed under the mean column....

Using across method

...

Using head method

The summarise method is used to create a summary of the values across the data rows that fall within one column. It is preferably used with a group_by method and the output data contains one row for each of the groups present in the column for which the group_by method is invoked. The method has the following syntax:...