0

I have to pick suppose 400 csv documents from a particular file.

For one file, i know it is read.csv("document1.csv")

However, I have a file suppose name file400. It has 400 documents starting from document1.csv to document400.csv. I have to make a function that selects all of them and take mean. I know i will use for(i in 400). However, i don't know how to select of file to read these documents.I can select my directory from setwd(file400).

But what should i do to read all 400 documents. I think i have to select a variable towards all these file400 contents. How will i do this? Once, i have a the variable set, for example xfile. I can put for (i in xfile). However, how can I assign xfile towards all file contents of file400?

It is very simple question. How can i upload all files in a directory in a function? How can i load more than one documents in read.csv()? This is the main question!

TAP
  • 1
  • 1
  • 3
  • look at the `list.files` function – jdharrison Jul 13 '14 at 10:24
  • Welcome to StackOverflow! Could you specify your question a bit more? Some suggested readings: [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to produce a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). This will make it much easier for others to help you. – Jaap Jul 13 '14 at 10:25
  • See [this Q&A](https://stackoverflow.com/questions/9564489/opening-all-files-in-a-folder-and-applying-a-function) – talat Jul 13 '14 at 10:27
  • The following answers I gave to more or less simular questions might help you as well: [answer 1](http://stackoverflow.com/questions/23930683/plot-many-csv-files-in-one-window/23954116#23954116) & [answer 2](http://stackoverflow.com/questions/23951541/importing-multiple-csv-file-into-r-by-names-of-file/23952165#23952165) – Jaap Jul 13 '14 at 10:33

1 Answers1

0

Try this:

fileNames <- lapply(1:400, function(x) paste("document",x,".csv",sep='')) data <- lapply(fileNames, function(x) read.csv(x, head=F))

Then you will have a list containing all 400 documents.

Y.Suze
  • 23
  • 4