[R] lapply drops colnames
Jack Tanner
ihok at hotmail.com
Mon Aug 2 23:03:51 CEST 2004
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?
More information about the R-help
mailing list