I have 2 data frames, M1[n,20] and M2[m,30]. If V1 and V2 are the same in both M1 and M2, then append V3-V30 from M2 onto M1. Otherwise, continue searching for a match. M1 is complete for all V1 and V2. M2 is missing observations for V1 or V2, or both. I can't figure this one out, except with reference to my old fortran-era skills. Help! [[alternative HTML version deleted]]
Below... On Mon, 8 Dec 2014, David Lambert wrote:> I have 2 data frames, M1[n,20] and M2[m,30].What does this mean? It might be intended to convey matrix dimensions, but these are not matrices and that is not R syntax.> If V1 and V2 are the same in both M1 and M2, then append V3-V30 from M2 onto M1.What does this mean? V3 is a default column label for data frames, but to just refer to V3 suggests an entire column, which doesn't make sense. If you mean individual values in the matching row, then where do you plan to put 27 values into M1?> Otherwise, continue searching for a match. > > > M1 is complete for all V1 and V2. M2 is missing observations for V1 or V2, or both. > > > I can't figure this one out, except with reference to my old fortran-era skills. Help! > > [[alternative HTML version deleted]]This desperately needs a reproducible example with a few matches and non-matches. Of course, if you email R code using HTML format it will likely get corrupted along the way, which is why the Posting Guide asks you to post in PLAIN TEXT format.> ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >--------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at 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
Have you looked at the merge() function? Here is an example. I don't know if it resembles your problem. > M1 <- data.frame(V1=letters[1:3], V2=LETTERS[26:24], N1=101:103) > M2 <- data.frame(V1=letters[c(3,1,2,3,2)], V2=LETTERS[c(23,26,22,24,24)], N2=c(1003,1001,1002,1003,1002)) > merge(M1,M2) V1 V2 N1 N2 1 a Z 101 1001 2 c X 103 1003 > merge(M1, M2, all.x=TRUE) V1 V2 N1 N2 1 a Z 101 1001 2 b Y 102 NA 3 c X 103 1003 > merge(M1, M2, all.y=TRUE) V1 V2 N1 N2 1 a Z 101 1001 2 b X NA 1002 3 b V NA 1002 4 c X 103 1003 5 c W NA 1003 Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Dec 8, 2014 at 8:42 AM, David Lambert <lambertd at ksu.edu> wrote:> I have 2 data frames, M1[n,20] and M2[m,30]. > > > If V1 and V2 are the same in both M1 and M2, then append V3-V30 from M2 > onto M1. > > > Otherwise, continue searching for a match. > > > M1 is complete for all V1 and V2. M2 is missing observations for V1 or > V2, or both. > > > I can't figure this one out, except with reference to my old fortran-era > skills. Help! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]