Hello, I am beginner in R and I would like to solve the following problem: Suppose that we have three files to be red in R d1, d2, and d3> d1id x1 x2 1 1 4 n 2 2 3 h 3 3 0 f> d2id x1 x2 1 1 2 r 2 2 3 u 3 3 1 f> d3id x1 x2 1 1 2 a 2 2 1 w Is there any library or function that one can read this datasets like for(i in 1:3) d[i] <- read.table(file=d[j].txt, header=T) and is it possible to delete the header for each file and to have them in one data frame like> d1 1 4 n 2 2 3 h 3 3 0 f 4 1 2 r 5 2 3 u 6 3 1 f 7 1 2 a 8 2 1 w 9 3 1 f I really appreciate your help! Stefo --------------------------------- [[alternative HTML version deleted]]
use something like the following (untested) files <- paste("C:/d", 1:3, ".txt", sep = "") dats <- vector("list", 3) for (i in 1:3) { dats[[i]] <- read.table(files[i], header = TRUE) } dats do.call("rbind", dat) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting Stefo Ratino <sratino at yahoo.com>:> Hello, > > I am beginner in R and I would like to solve the following problem: > Suppose that we have three files to be red in R d1, d2, and d3 > >> d1 > id x1 x2 > 1 1 4 n > 2 2 3 h > 3 3 0 f >> d2 > id x1 x2 > 1 1 2 r > 2 2 3 u > 3 3 1 f >> d3 > id x1 x2 > 1 1 2 a > 2 2 1 w > > Is there any library or function that one can read this datasets like > for(i in 1:3) > d[i] <- read.table(file=d[j].txt, header=T) > > and is it possible to delete the header for each file and to have > them in one data frame like > >> d > 1 1 4 n > 2 2 3 h > 3 3 0 f > 4 1 2 r > 5 2 3 u > 6 3 1 f > 7 1 2 a > 8 2 1 w > 9 3 1 f > > I really appreciate your help! > Stefo > > > > > > > --------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
En indlejret tekst med ukendt tegns?t er blevet fjernet... Navn: ikke tilg?ngelig Url: https://stat.ethz.ch/pipermail/r-help/attachments/20071014/8accfb95/attachment.pl
Hi "Klaus Friis ?stergaard" <farremosen at gmail.com> napsal dne 16.10.2007 10:34:15:>> 2007/10/15, Petr PIKAL <petr.pikal at precheza.cz>: > Hi > > > Well, let us put it another way. Do you want for each unique combination > of Hole and Feature to subtract a value from one data frame, let us call > it nom from another data frame, let us call it raw? If yes I assume you > have exactly same number of unique combinations of Hole and Featurevalues> in both datasets. > > In that case you can use such for cycle (although there can be otherfiner> solutions) > > for (i in 1:no.of.unique.levels ) { > selection <- interaction(raw$hole, raw$feature) %in%interaction(nom$hole,> nom$feature)[1] > raw[selection,"value"] <- raw[selection,"value"]-nom[i,"value"] > } > > I had to move on with the project and did a ruby script out side thatput the> right values in the rawdata. > > But I will surely return to look at this solution. > > I question in the non table the combinations of Feature and Hole areunique is> it possible to calculate this on the fly in R?Yes. If your next question is how, you can look at ?duplicated. Regards Petr> > > > -- > Klaus F. ?stergaard, <farremosen(at)gmail dot com>