Row wise operation in R using Dplyr

Row wise operation in R can be performed using rowwise() function in dplyr package. Dplyr package is provided with rowwise() function with which we will be doing row wise maximum or row wise minimum operations.

We will be using iris data to depict the example of rowwise() function.

library(dplyr)

mydata2 <-iris 
head(mydata2)

iris data will be looking like

case when statement in R dplyr 1

 

We will be creating additional variable row_max using mutate function and rowwise() function to store the row wise maximum variable.

df1 = mydata2 %>%
  rowwise() %>% mutate(row_max= max(Sepal.Length:Petal.Width))

head(df1)

So the snapshot of resultant data frame will be

rowwise function in R dplyr

Row wise operation in R using Dplyr                                                                                                         Row wise operation in R using Dplyr

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.