0

I am trying to right a function that includes the $ operator to specify a column in a data frame. Is there a way to do this?

Here is an example of what I've tried:

library(lubridate)
library(tidyverse)
library(purrr)

ID <- rep(c("A","B", "C"), 200)
df <- data.frame(x = runif(length(date), min = 60000, max = 80000),
                 y = runif(length(date), min = 800000, max = 900000),
                 ID)


func <- function(z){
  mean(df$z)
}

# attempt at using the column `x` in `df`
func(x)

John Huang
  • 765
  • 2
  • 13

0 Answers0