[R] importing multiple file form folder

Rui Barradas ruipbarradas at sapo.pt
Sun Jun 10 00:39:29 CEST 2012


Hello,

'cbind' means column bind and 'rbind', row bind.
So, apparently, all you have to do is replace one letter.
ONLY in the do.call, it will surelly do what you want, my only doubt is 
with cbinding the Length column, it should recycle the values.

Hope this helps,

Rui Barradas

Em 09-06-2012 23:25, mpavlic escreveu:
>
> Hi all,
>
> i managed to (with the help of most posts here) using bellow code :
>
> 	>setwd("C:/Users/mpavlic/Desktop/test")
> 	>txt_files = list.files(pattern = '*.ddf');
> 	>flist<-txt_files
> 	>flistNew <- sub("^channel 1 ([0-9 ]+).*", "\\1", flist)
> 	>coordinate<-read.csv("coordinate_linija1.csv", sep=";", dec=".")[,2:4]
>
> 	>Length <- read.table(flist[1], skip=917, nrows=970)[, 1]
> 	>Temp <- do.call(cbind, lapply(flist, function(x) read.table(x, skip=917,
> nrows=970)[, 2]))
> 	>colnames(Temp) <- paste(flistNew, seq_len(ncol(Temp)), sep=".")
> 	>result <- cbind(Length=Length, coordinate, Temp)
>
> ...join all files in one folder in one big table. But the merging here is
> done by columns as seen in attachment-asColumns.csv (so that every column
> form certain file is added to the table "result" as a column).
>
> For better reperesentation of data I would now need data to be added as rows
> in a table, with corresponding name of the file as a value in column.
> Resulting table should look something like in an attached file asRows.csv.
> Is that possible?
>
> Hope i exaplined it ok, because it's a bit difficult. Thanks for any
> idea....
> http://r.789695.n4.nabble.com/file/n4632909/asColumns.csv asColumns.csv
> http://r.789695.n4.nabble.com/file/n4632909/asRows.csv asRows.csv
>
> --
> View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4632909.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list