0

I have several .txt files in a folder.

I want to read all the files, so, I used > files = list.files()

But how can I merge all text files in to one file ? ( There each text files have not same length, so I used readlines )

Please tell me how to get all text files in one file and there have one column with its source file name.

Example - ex01.txt ( three column) some column have NA values ex02.txt ( Five colunm) some column have NA values ex03.txt ( Six colunm) some column have NA values ex04.txt ( Eight column) some column have NA values

Need output :

Those Eight column + one additional column (this column will contain file name)

                    ex01.txt
                    ex01.txt
                    ex02.txt
                    ex02.txt 
                    ex03.txt
                    ex03.txt 
  • 1
    Some example data would be nice. Perhaps `library(data.table); lst <- lapply(files, fread); dt <- rbindlist(lst, fill=TRUE); dt[,filenm:=rep(files, sapply(lst,nrow))]` ` – akrun Jan 13 '15 at 16:40
  • Perhaps http://stackoverflow.com/questions/27747716/how-to-merge-multiple-excel-files/27748245#27748245 could help you if you actually want to _merge_ the files. – talat Jan 13 '15 at 16:42

0 Answers0