1

I have about 200 txt files with different name, any file have diferent number of dimensions. The code for read is ok:

setwd("C:/...")
filelist<-list.files(pattern="*.txt")
for (j in 1:length(filelist)) assign(filelist[j], read.csv(filelist[j], header=TRUE))

But I want a loop about to read all of the above files and data variable to gets each file each time.

for (file in filelist){
    data[file]<-file
    Do something with data
    e.g. log(data[,6]
}

From the above the output from data is
"NameFile.txt"
The problem is that in this way does not read the data set just the name of data. There is a way to to chase away the "" or something else?

Cache Staheli
  • 3,510
  • 7
  • 32
  • 51
  • Please, show the contents of `filelist`. – Uwe Jun 18 '16 at 05:58
  • 1
    It should be more convenient to [store your data in a "list"](http://stackoverflow.com/questions/11433432/importing-multiple-csv-files-into-r); i.e. `all_csv = setNames(lapply(filelist, read.csv, header = TRUE), filelist)` and, then, operate with `lapply` : `lapply(all_csv, function(data) log(data[, 6]))` etc. – alexis_laz Jun 18 '16 at 11:18

1 Answers1

0

You may want to do one of the following in your for loop, the second suggested by @hvollmeier.

for (file in filelist){
    ## Uncomment one of these options
    #=> data[file] <- eval(parse(text = file))
    # OR
    #=> data[file] <- get(file)

    Do something with data
    e.g. log(data[,6])
}
steveb
  • 5,382
  • 2
  • 27
  • 36