An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100105/46ec6e1c/attachment.pl>
Dynamic arguments in "rbind" function
3 messages · Steven Kang, Sundar Dorai-Raj, Duncan Murdoch
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100104/076a3b7a/attachment.pl>
On 04/01/2010 7:31 PM, Steven Kang wrote:
Hi, all
Basically, I have unknown number of data that need to be imported and
collapsed row-wisely.
The code below works fine, however the "rbind" function may require 50
arguments if there are 50 data files...
Thus, I would like to explore whether there are any methods in using dynamic
objects (i.e from the resulting objects in the for loop) as an argument in
the *"rbind"* function.
setwd(.........)
import.files <- c("a.txt", "b.txt", "c.txt", "d.txt", "e.txt")
for (i in 1:length(import.files)) {
assign(paste("imp", i, sep = "."), read.delim(eval(paste(".\\",
import.files[i], sep = "")), header = TRUE))
Computing names like this is almost always a bad idea. It's better to
just put the items in a list:
imp <- list()
for (i in 1:length(import.files)) {
imp[[i]] <- read.delim(eval(paste(".\\",
import.files[i], sep = "")), header = TRUE)
}
Then to bind them all, simply use do.call(rbind, imp).
Duncan Murdoch
} combined <- rbind(*imp.1, imp.2, imp.3, imp.4, imp.5, imp.6*) Your expertise in resolving this issue would be greatly appreciated. Steve [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list 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.