An explanation of the merge of R language

Source: Internet
Author: User

Declaration of the Merge function:

Merge (x, y, by = intersect (names (x), names (y)), by.x = by, By.y = by, all = FALSE, all.x = all, All.y = all, sor t = TRUE, suffixes = C (". X", ". Y"), incomparables = NULL, ...)

Description of the merge function parameter:

X, y: Two data frames for merging

BY,BY.X,BY.Y: Specifies which rows are to be combined with the data frame, with the default value being the column with the same column name.

ALL,ALL.X,ALL.Y: Specifies whether the rows of x and y should be all in the output file.

Sort:by whether the specified column is to be sorted.

Suffixes: Specifies the suffix of the same column name, except by.

Incomparables: Specifies which cells in by are not merged.


Example:

w1:name    school     CLASS    ENGLISHA    S1    10     85B    S2    5    50A     S1    4    90A    S1     11    90C    S1    1     12w2:NAME    SCHOOL    CLASS    MATHS     ENGLISHA    S3    5    80     88B    S2    5    89     81C    S1    1    55     32 

     Merge W1 and W2 by name, SCHOOL, class:

Merge (W1, w2, all = t) &NBSP;&NBSP;NAME&NBSP;SCHOOL&NBSP;CLASS&NBSP;ENGLISH&NBSP;MATHS1     A     S1     4       90    NA2    A     S1     10      85    na3    a      S1    11      90     NA4    A     S3     5       88    805    B      S2     5      50    NA6     B     S2     5       81    897    c     s1     1       12    NA8    C      s1     1      32    55merge ( W1, w2, by = c ("NAME",  "SCHOOL",  "CLASS"),  all = t)    name school class english.x maths english.y1    a      S1     4        90     NA        NA2    A      S1    10        85     NA        NA3    A      s1    11        90    na         NA4    A     S3      5        NA    80         885    B     S2      5        50    89         816    C     S1      1        12    55         32merge (w1, w2, all = t, incomparables =  "A") Error  in merge.data.frame (w1, w2, all = t, incomparables =  "A")  :    ' Incomparables'  is supported only for merging on a single columnmerge (w1,  w2, all = t, by =  "NAME", incomparables =  "A")   NAME  SCHOOL.x CLASS.x ENGLISH.x SCHOOL.y CLASS.y MATHS ENGLISH.y1     A       S1      10         85     <NA>       na    na        na2    a        S1       4         90     <na>      na     NA        NA3    A        s1      11        90      <NA>      NA    NA         NA4    A     <NA>       NA        NA        S3       5    80         885    B       S2        5        50        S2       5    89         816    c       s1        1        12       s1        1    55         32


An explanation of the merge of R language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.