0

I have some data and I am trying to see if there is a relationship between the columns and the SalePrice column. In order to do this, I have created a function that that groups the values in the columns that are the same and averages the SalePrice.

 continuousVSalePrice <- function(contVar) {
  group <- train %>% group_by(contVar)
  group <- group %>% summarise(
    SalePrice = mean(SalePrice)
  )
  ggplot(data=group, aes(x=contVar, y=SalePrice, group=1)) +
    geom_line()+
    geom_point()
}

continuousVSalePrice(OverallQuality)

However when I run this code with R, contVar is getting executed when it reads the function, instead of OverallQuality. Therefore, the error I get when it is run is...

* Column contVar is not found.
Run `rlang::last_error()` to see where the error occurred.

Is there any way to make it so that the function is not executed when it is read, only when a parameter is passed? Kind of like lazy-loading.

joey
  • 115
  • 8

0 Answers0