This can't be done, except how you've done it with for
. If you want to return a structure with the results (and would be appending to a list, for example), *apply
may still be appropriate.
x <- lapply(names(iris), function(name) {
cat("processing col", name, "\n")
iris[[name]]
})
## processing col Sepal.Length
## processing col Sepal.Width
## processing col Petal.Length
## processing col Petal.Width
## processing col Species
names(x) <- names(iris)
x
is now a list containing the columns of the data frame iris
.