Much thanks, Hadley!

Cheers,
Alan

On Jan 29, 2015, at 12:36 PM, Hadley Wickham wrote:

> On Thu, Jan 29, 2015 at 11:43 AM, Alan Yong <alany...@caltech.edu> wrote:
>> Much thanks to everyone for their recommendations!  I agree that fishing in 
>> the global environment isn't ideal & only shows my budding understanding of 
>> R.
>> 
>> For now, I will adapt Chel Hee's "length(eval(parse(text=DFName))[,1])" 
>> solution then fully explore Jeff's suggestion to put the data frames into a 
>> list.
> 
> If you have to go down this route, at least do nrow(get(DFName))
> 
>> (1) Add a column to each data frame with a string that is parsed from the 
>> appendage of the data frame name, i.e., string is "1001" from data frame 
>> object of "df.1001"; then,
>> (2) Bind the rows of all the files.
> 
> I'd highly recommend learning a little functional programming such as
> the use of lapply (e.g. http://adv-r.had.co.nz/Functionals.html).
> Then you can easily do:
> 
> csvs <- dir(pattern = "\\.csv$")
> all <- lapply(csvs, read.csv)
> one <- do.call("rbind", all)
> 
> to find all the csv files in a directory, load into a list and then
> collapse into a single data frame.
> 
> You're much better off learning how to do this than futzing around
> with named objects in the global environment.
> 
> Hadley
> 
> -- 
> http://had.co.nz/

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to