r - Invalid type (closure) for a variable that is not a function -
loess.smooth <- function(dat) { dat <- dat[complete.cases(dat),] ## response vars <- colnames(dat) ## covariate id <- 1:nrow(dat) ## define loess filter function (fitting loess regression line) loess.filter <- function (x, span) loess(formula = paste(x, "id", sep = "~"), data = dat, degree = 1, span = span)$fitted ## apply filter column-by-column new.dat <- as.data.frame(lapply(vars, loess.filter, span = 0.75), col.names = colnames(dat)) } when try apply loess.smooth dataframe, error: error in model.frame.default(formula = paste(x, "id", sep = "~"), data = dat) : invalid type (closure) variable 'id' i don't understand why problem since id not function, implied error. when run through these lines of code outside of function, wo...