Perform a SUMIF Function on All Columns
In this method to perform a sumif function on all the columns of the given dataframe, the user needs to simply call the aggregate() function of base R and pass the name of the data frame as the parameter into it as shown in the syntax below to get the result to the performing the sumif function on the entire data frame in the R language.
Syntax:
aggregate(. ~ group_column, dataframe, sum)
Example:
In this example, we are performing the sumif operation on subjects by performing a group to get the sum of all columns using the aggregate() function in the R language.
R
# create a dataframe data= data.frame (id= c (1,2,3,4,5), subjects= c ( 'java' , 'php' , 'java' , 'php' , 'php' ), marks= c (100,98,90,87,89)) # sumif operation on subjects by # performing group to get sum of all columns print ( aggregate (. ~ subjects, data, sum)) |
Output:
subjects id marks 1 java 4 190 2 php 11 274
How to Perform a SUMIF Function in R?
In this article, we will discuss the sumif function in R Programming Language.
This function is used to group the data and get the sum of the values by a group of values in the dataframe, so we are going to perform this operation on the dataframe.