Jack Tanner hotmail.com> writes:
>
> Wolski wrote:
> > What you can do is to extend the column (list) by an addtional attribute
> attr(mydataframe[i],"info")<-names(mydataframe)[i] and store theyr names in
it.
>
> OK, that's brilliant. Any ideas on how to do this automatically for
> every co
If you were preferring to use lapply() rather than for() for reasons of
efficiency,you might want to test whether there actually is any
difference. In a little test case, involving a data frame with 10,000
columns, I see no big difference. The advantage of a for loop in your
situation is that
Wolski wrote:
What you can do is to extend the column (list) by an addtional attribute attr(mydataframe[i],"info")<-names(mydataframe)[i] and store theyr names in it.
OK, that's brilliant. Any ideas on how to do this automatically for
every column in my dataframe? lapply(dataframe... fails for th
Hi!
The (column) - names are a property of the data.frame (list - from which data.frame
inherits (at least theoretically (green book) how it is implemented in R I do not
know.) The columns of the data.frame are lists again. The data.frama is the box and a
column is a list in the data.frame list
Seems like you got your input and output mixed up a bit...
> From: Jack Tanner
>
> 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)
Yo
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
NU