On Jul 6, 2011, at 7:36 AM, Silvano wrote:> ----- Original Message ----- From: "Silvano" <silvano at uel.br> > To: <r-help at r-project.org> > Sent: Thursday, June 30, 2011 9:07 AM > Subject: Tables and merge > >> I have 21 files which is common variable CODE. >> Each file refers to a question. >> >> I would like to join the 21 files into one, to construct >> tables for each question by CODE. >> >> I tried the command (8 files only): >> >> require(foreign) >> q1 = read.epiinfo('Dados/Q1.rec') >> q2 = read.epiinfo('Dados/Q2.rec') >> q3 = read.epiinfo('Dados/Q3.rec') >> q4 = read.epiinfo('Dados/Q4.rec') >> q5 = read.epiinfo('Dados/Q5.rec') >> q6 = read.epiinfo('Dados/Q6.rec') >> q7 = read.epiinfo('Dados/Q7.rec') >> q8 = read.epiinfo('Dados/Q8.rec') >> >> juntos = merge(q1,q2,q3,q4,q5,q6,q7,q8) >> >> But it didn't work. Any suggestions?Suggestion # 1: Read the Posting Guide. In there you are advised to report the verbatim text from error messages. Reading error messages is often informative. Suggestion # 2: Report the results of `str` on all of those "q" objects. We need to see whether there are the necessary common column names that would support a merge operation. Suggestion #3 : read the ?merge page and pay particular attention to number ("two") in the title. consider this possibility after further reading of ?merge and a bit of testing. merge(x=q1, y=list(q2,q3,q4,q5,q6,q7,q8) ) # Your error occurred because of positional matching. The q3 object is being assigned to the third argument , "by= ", and that is what your unreported error message was telling you. That construction seemed to work without error on a test I did with a slight modification of the first example on ?merge. After making the author column have the same name = `name`, I also got success with: do.call("merge", list(x=authors, y=list(books, books))) The non-do,call simplification above was not entirely predictably correct (to me anyway) , since the ?merge page does not say that a list object holding dataframes would be an acceptable "y" argument. But I see that as.data.frame(list(books, books)) does produce a data.frame and coercion with as.data.frame on that list object is probably what happened in the merge() call. -- David Winsemius, MD West Hartford, CT
Merge can only handle two tables at a time. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Silvano <silvano@uel.br> wrote: ----- Original Message ----- From: "Silvano" <silvano@uel.br> To: <r-help@r-project.org> Sent: Thursday, June 30, 2011 9:07 AM Subject: Tables and merge> Hi, > > I have 21 files which is common variable CODE. > Each file refers to a question. > > I would like to join the 21 files into one, to construct > tables for each question by CODE. > > I tried the command (8 files only): > > require(foreign) > q1 = read.epiinfo('Dados/Q1.rec') > q2 = read.epiinfo('Dados/Q2.rec') > q3 = read.epiinfo('Dados/Q3.rec') > q4 = read.epiinfo('Dados/Q4.rec') > q5 = read.epiinfo('Dados/Q5.rec') > q6 = read.epiinfo('Dados/Q6.rec') > q7 = read.epiinfo('Dados/Q7.rec') > q8 = read.epiinfo('Dados/Q8.rec') > > juntos = merge(q1,q2,q3,q4,q5,q6,q7,q8) > > But it didn't work. Any suggestions? > > Thank you. > >_____________________________________________> Silvano Cesar da Costa > Departamento de Estatística > Universidade Estadual de Londrina > Fone: 3371-4346 >_____________________________________________>_____________________________________________ R-help@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. [[alternative HTML version deleted]]
Silvano, I have some examples using merge() from my class notes in http://www.leg.ufpr.br/doku.php/disciplinas:ce223-2011-01. See "aula11.R". For the moment, this minimal reproducible code can be useful id <- 1:30 n <- 20 a1 <- data.frame(id=sample(id, n), v1=rnorm(n)) a2 <- data.frame(id=sample(id, n), v2=rpois(n,10)) a3 <- data.frame(id=sample(id, n), v3=runif(n)) merge(a1, a2, by="id") # just two data.frame at once a0 <- list(a1, a2, a3) Reduce(function(x, y) merge(x, y, by="id"), a0, accumulate=FALSE) # font: http://rwiki.sciviews.org/doku.php?id=tips:data-frames:merge You can also join to the R-br mailing list (brazilian R-help list). Instructions in http://www.leg.ufpr.br/doku.php/software:rbr Bests. Walmes. =========================================================================Walmes Marques Zeviani LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W) Departamento de Estatística - Universidade Federal do Paraná fone: (+55) 41 3361 3573 VoIP: (3361 3600) 1053 1173 e-mail: walmes@ufpr.br twitter: @walmeszeviani homepage: http://www.leg.ufpr.br/~walmes linux user number: 531218 ========================================================================= [[alternative HTML version deleted]]
----- Original Message ----- From: "Silvano" <silvano at uel.br> To: <r-help at r-project.org> Sent: Thursday, June 30, 2011 9:07 AM Subject: Tables and merge> Hi, > > I have 21 files which is common variable CODE. > Each file refers to a question. > > I would like to join the 21 files into one, to construct > tables for each question by CODE. > > I tried the command (8 files only): > > require(foreign) > q1 = read.epiinfo('Dados/Q1.rec') > q2 = read.epiinfo('Dados/Q2.rec') > q3 = read.epiinfo('Dados/Q3.rec') > q4 = read.epiinfo('Dados/Q4.rec') > q5 = read.epiinfo('Dados/Q5.rec') > q6 = read.epiinfo('Dados/Q6.rec') > q7 = read.epiinfo('Dados/Q7.rec') > q8 = read.epiinfo('Dados/Q8.rec') > > juntos = merge(q1,q2,q3,q4,q5,q6,q7,q8) > > But it didn't work. Any suggestions? > > Thank you. > > -------------------------------------- > Silvano Cesar da Costa > Departamento de Estat?stica > Universidade Estadual de Londrina > Fone: 3371-4346 > -------------------------------------- >