0

I was just trying to call a certain column inside an R function using the code below but it only returns a null value. I know it sounds stupid to call the column using the $ sign. I know it can be done by defining the targeted column directly in the input of the function. However, I just want to know why the code below is not working. Thanks in advance!

fn <- function(data, var){
  return(data$var)
}
data(cars)
fn(cars, speed)
Izak
  • 21
  • 2
  • 1
    The various alternatives as well as the answer to "why doesn't `$` work" are included in various answers there, though you may need to read more than one answer. – joran Jul 23 '18 at 22:24
  • Thank you! I wasn't using the right keywords to search for a solution. I should've dug deeper before posting my question. – Izak Jul 24 '18 at 17:05

0 Answers0