I want to iterate over a data frame by columns, and as I'm processing each column I want to know its column name.

> a <- as.data.frame(list(1,2,3))
> colnames(a) <- c("a", "b", "c")
> colnames(a)
[1] "X1" "X2" "X3"
> lapply(a, function(x) {print(colnames(x))})
NULL
NULL
NULL
$a
NULL

$b
NULL

$c
NULL

What is lapply doing? Why does it drop the column name of every column it's iterating over? How can I get the column name as a string?

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to