The mutate() function in dplyr package in R is used to derive new variables from existing variables (not from existing observations). For existing observations, one needs to use summarise() function instead. Below is an example: If we take a sample data from “nycflights13” dataset, and try to view top few records, it looks like as below.   Now, if we use the mutate() function to derive a new variable and use select() function to fetch selected columns from above data frame. flights <- as.data.frame(flights)
flights_mutate <- flights %>% mutate(speed=distance/air_time*60) %>% select(carrier,arr_delay,speed) This will give below desired result. (again, few records shown from the data frame). Here the new derived variable is “speed” which is computed and derived based on the formula [distance / air_time*60]