[R] recursive methods for concatenating sets of files

jim holtman jholtman at gmail.com
Wed Sep 13 23:31:07 CEST 2006


Try this:

setwd("d:/perf/windows")  # wherever your data is
results <- list()
for (i in list.files(pattern="t.*txt$")){   # need the 'pattern' of the names
    results[[i]] <- read.delim(i, quote='', as.is=TRUE)
}
dataALL <- do.call('cbind', results)
write.table(dataALL,"0905p528.txt", quote=FALSE)


On 9/13/06, Warren <geelewis at gmail.com> wrote:
> Hello,
>
> I would like to read sets of files within a folder, perhaps using recursive
> methods.
>
> Right now, I rename the files before import.
> It would be even better to do this without renaming files, without providing
> explicit filenames, perhaps by importing files based on chronology,
> and translating each filename into a header?
>
> Please excuse my ignorance, and help cure my clunky programming
> (below) with more elegant code.
>
> Thanks,
> Warren
>
>
>
>
>
> data0 <-read.delim("t.txt", quote="", as.is=TRUE)
>
> data1 <-read.delim("t (1).txt", quote="", as.is=TRUE)
>
> data2 <-read.delim("t (2).txt", quote="", as.is=TRUE)
>
> data3 <-read.delim("t (3).txt", quote="", as.is=TRUE)
>
> data4 <-read.delim("t (4).txt", quote="", as.is=TRUE)
>
> data5 <-read.delim("t (5).txt", quote="", as.is=TRUE)
>
> data6 <-read.delim("t (6).txt", quote="", as.is=TRUE)
>
> data7 <-read.delim("t (7).txt", quote="", as.is=TRUE)
>
> data8 <-read.delim("t (8).txt", quote="", as.is=TRUE)
>
> data9 <-read.delim("t (9).txt", quote="", as.is=TRUE)
>
> data10 <-read.delim("t (10).txt", quote="", as.is=TRUE)
>
> data11 <-read.delim("t (11).txt", quote="", as.is=TRUE)
>
> data12 <-read.delim("t (12).txt", quote="", as.is=TRUE)
>
> data13 <-read.delim("t (13).txt", quote="", as.is=TRUE)
>
> data14 <-read.delim("t (14).txt", quote="", as.is=TRUE)
>
> data15 <-read.delim("t (15).txt", quote="", as.is=TRUE)
>
> data16 <-read.delim("t (16).txt", quote="", as.is=TRUE)
>
> data17 <-read.delim("t (17).txt", quote="", as.is=TRUE)
>
> data18 <-read.delim("t (18).txt", quote="", as.is=TRUE)
>
> data19 <-read.delim("t (19).txt", quote="", as.is=TRUE)
>
> data20 <-read.delim("t (20).txt", quote="", as.is=TRUE)
>
> data21 <-read.delim("t (21).txt", quote="", as.is=TRUE)
>
> data22 <-read.delim("t (22).txt", quote="", as.is=TRUE)
>
> data23 <-read.delim("t (23).txt", quote="", as.is=TRUE)
>
> data24 <-read.delim("t (24).txt", quote="", as.is=TRUE)
>
> data25 <-read.delim("t (25).txt", quote="", as.is=TRUE)
>
> data26 <-read.delim("t (26).txt", quote="", as.is=TRUE)
>
> data27 <-read.delim("t (27).txt", quote="", as.is=TRUE)
>
> data28 <-read.delim("t (28).txt", quote="", as.is=TRUE)
>
> data29 <-read.delim("t (29).txt", quote="", as.is=TRUE)
>
> data30 <-read.delim("t (30).txt", quote="", as.is=TRUE)
>
> data31 <-read.delim("t (31).txt", quote="", as.is=TRUE)
>
> data32 <-read.delim("t (32).txt", quote="", as.is=TRUE)
>
> data33 <-read.delim("t (33).txt", quote="", as.is=TRUE)
>
> data34 <-read.delim("t (34).txt", quote="", as.is=TRUE)
>
> data35 <-read.delim("t (35).txt", quote="", as.is=TRUE)
>
> data36 <-read.delim("t (36).txt", quote="", as.is=TRUE)
>
> data37 <-read.delim("t (37).txt", quote="", as.is=TRUE)
>
> data38 <-read.delim("t (38).txt", quote="", as.is=TRUE)
>
> data39 <-read.delim("t (39).txt", quote="", as.is=TRUE)
>
> data40 <-read.delim("t (40).txt", quote="", as.is=TRUE)
>
> data41 <-read.delim("t (41).txt", quote="", as.is=TRUE)
>
> data42 <-read.delim("t (42).txt", quote="", as.is=TRUE)
>
> data43 <-read.delim("t (43).txt", quote="", as.is=TRUE)
>
> data44 <-read.delim("t (44).txt", quote="", as.is=TRUE)
>
> data45 <-read.delim("t (45).txt", quote="", as.is=TRUE)
>
> data46 <-read.delim("t (46).txt", quote="", as.is=TRUE)
>
> data47 <-read.delim("t (47).txt", quote="", as.is=TRUE)
>
> data48 <-read.delim("t (48).txt", quote="", as.is=TRUE)
>
> data49 <-read.delim("t (49).txt", quote="", as.is=TRUE)
>
> data50 <-read.delim("t (50).txt", quote="", as.is=TRUE)
>
> data51 <-read.delim("t (51).txt", quote="", as.is=TRUE)
>
> data52 <-read.delim("t (52).txt", quote="", as.is=TRUE)
>
> data53 <-read.delim("t (53).txt", quote="", as.is=TRUE)
>
> data54 <-read.delim("t (54).txt", quote="", as.is=TRUE)
>
> data55 <-read.delim("t (55).txt", quote="", as.is=TRUE)
>
> data56 <-read.delim("t (56).txt", quote="", as.is=TRUE)
>
> data57 <-read.delim("t (57).txt", quote="", as.is=TRUE)
>
> data58 <-read.delim("t (58).txt", quote="", as.is=TRUE)
>
> data59 <-read.delim("t (59).txt", quote="", as.is=TRUE)
>
> data60 <-read.delim("t (60).txt", quote="", as.is=TRUE)
>
> data61 <-read.delim("t (61).txt", quote="", as.is=TRUE)
>
> data62 <-read.delim("t (62).txt", quote="", as.is=TRUE)
>
> data63 <-read.delim("t (63).txt", quote="", as.is=TRUE)
>
> data64 <-read.delim("t (64).txt", quote="", as.is=TRUE)
>
> data65 <-read.delim("t (65).txt", quote="", as.is=TRUE)
>
> data66 <-read.delim("t (66).txt", quote="", as.is=TRUE)
>
> data67 <-read.delim("t (67).txt", quote="", as.is=TRUE)
>
> data68 <-read.delim("t (68).txt", quote="", as.is=TRUE)
>
> data69 <-read.delim("t (69).txt", quote="", as.is=TRUE)
>
> data70 <-read.delim("t (70).txt", quote="", as.is=TRUE)
>
> data71 <-read.delim("t (71).txt", quote="", as.is=TRUE)
>
> data72 <-read.delim("t (72).txt", quote="", as.is=TRUE)
>
> data73 <-read.delim("t (73).txt", quote="", as.is=TRUE)
>
> data74 <-read.delim("t (74).txt", quote="", as.is=TRUE)
>
> data75 <-read.delim("t (75).txt", quote="", as.is=TRUE)
>
>
>
> dataALL
> <-cbind(data0,data1,data2,data3,data4,data5,data6,data7,data8,data9,data10,data11,data12,data13,data14,data15,data16,data17,data18,data19,data20,data21,data22,data23,data24,data25,data26,data27,data28,data29,data20,data31,data32,data33,data34,data35,data36,data37,data38,data39,data40,data41,data42,data43,data44,data45,data46,data47,data48,data49,data50,data51,data52,data53,data54,data55,data56,data57,data58,data59,data60,data61,data62,data63,data64,data65,data66,data67,data68,data69,data70,data71,data72,data73,data74,data75)
>
>
>
> write.table(dataALL,"0905p528.txt", quote=FALSE)
> --
> geelewis at gmail.com
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list