Skip to content
Prev 164428 / 398503 Next

call lattice function in a function passing

Here's one approach.  Pass the 'groups' variable as a character, then find 
that variable in the data frame and rename it.

d <- data.frame(x = rnorm(100), y = c("a", "b"))

f <- function(data, groupvar) {
	names(data)[which(names(data) == groupvar)] <- "gp"
  	densityplot(~ x, data, groups = gp)
}

f(d, groupvar="y")