Re: [R] How to write a list object's name to a new dataframe in that list object

2011-10-07 Thread Bert Gunter
SImpler: for(nm in names(L) ) L[[nm]] [[nm]] <- nm However, note that you could also attach the name to each data frame as a, say, "name" attribute and avoid the extra column. -- Bert On Fri, Oct 7, 2011 at 8:42 PM, R. Michael Weylandt < michael.weyla...@gmail.com> wrote: > It's inefficient b

Re: [R] How to write a list object's name to a new dataframe in that list object

2011-10-07 Thread R. Michael Weylandt
It's inefficient but try this: Suppose your list is L: mapply(function(x,y) cbind(x, data.frame(NAME=rep(y,NROW(x, L, names(L), simplify = F) Code is untested however - let me know if this doesn't work and I'll get to a computer and clean it up. Michael Weylandt On Oct 7, 2011, at 11:1

[R] How to write a list object's name to a new dataframe in that list object

2011-10-07 Thread Mark Na
Hello R-helpers, I have a list that only contains dataframes. Each element of the list (i.e., each dataframe) has a unique name ("one" through "ten"). I wish to add a new column (called "NAME") to each list element (i.e each datarame) and I want that column to contain the name of it's list element