Re: [R] lapply drops colnames

2004-08-02 Thread Gabor Grothendieck
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

Re: [R] lapply drops colnames

2004-08-02 Thread Tony Plate
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

Re: [R] lapply drops colnames

2004-08-02 Thread Jack Tanner
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

Re: [R] lapply drops colnames

2004-08-02 Thread Wolski
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

RE: [R] lapply drops colnames

2004-08-02 Thread Liaw, Andy
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

[R] lapply drops colnames

2004-08-02 Thread 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) [1] "X1" "X2" "X3" > lapply(a, function(x) {print(colnames(x))}) NULL NULL NULL $a NULL $b NULL $c NU