0

Below is what i want to achieve by writing a function by passing a data frame and column name as arguments. Selecting a column and then creating a calculated field

mtcars %>%  
       select(mpg, cyl, disp, hp, drat, wt, qsec) %>%  
        mutate(delta = disp-mpg)

Below is the function i created:

test_function <- function(df,column_name) {
       df %>%  
       select(mpg, cyl,column_name , hp, drat, wt, qsec) %>%  
        mutate(delta = column_name-mpg) 
        
        
}

test_function(mtcars, disp)

Getting the below error: Error: object 'disp' not found

saura
  • 1
  • 1

0 Answers0