Hello R-list,
I have a batch of files that I want to turn into R data.frames for
analysis. I'd like to use a for loop to read.table into data frame and
name the data.frame after the source file. Here's the code I've tried:
files_list.files(".")
for(i in 1:length(list.files("."))-1){
parse(text=files[i])[[1]]_read.table(files[i],as.is=TRUE)
}
AFIK, the problem lies in the way I'm trying to name the data.frame.
I have spent some time pouring over the R documentation, but if the answer
was there I missed it. Any reference to the manuals or quick fix would be
appreciated.
David
S. David White
sdavidwhite at bigfoot.com
Columbus, Ohio
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
naming data.frames after their source file
2 messages · David White, Uwe Ligges
David White wrote:
Hello R-list,
I have a batch of files that I want to turn into R data.frames for
analysis. I'd like to use a for loop to read.table into data frame and
name the data.frame after the source file. Here's the code I've tried:
files_list.files(".")
for(i in 1:length(list.files("."))-1){
parse(text=files[i])[[1]]_read.table(files[i],as.is=TRUE)
}
If you really want to use the filenames, be sure these filenames are also valid names in R! assign(eval(files[i]), read.table(files[i], as.is = TRUE)) In most cases it is much easier to use a list of data.frames: my.data[[i]] <- read.table(files[i], as.is=TRUE)
AFIK, the problem lies in the way I'm trying to name the data.frame. I have spent some time pouring over the R documentation, but if the answer was there I missed it. Any reference to the manuals or quick fix would be appreciated.
Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._