简体   繁体   中英

Group a table by unique IDs in R

I have a table like this below. I need to group then by unique POL, PLAN, ID1 and ID2

Output table is shown below.

Any help is appreciated.

dfx1:

YEAR    POL    CTY    PLAN  TYPE  ID1  ID2  DATE
1998  4680     133    90    11    6    1    10061997
1998  4680     133    90    11    8    2    10041997
1998  4772     133    44    11   10    1    11011997
1998  6407     133    44    11   23    7    10231997
1999  7371     133    44    11   24    1    11041997
1999  4680     133    90    11    6    1    10021998 
1999  4680     133    90    11    8    2    10061998
1999  4772     133    44    11   10    1    11051998
1999  6407     133    44    11   23    7    10241998
2000  7371     133    44    11   24    1    11061999

Output:

YEAR    POL    CTY    PLAN  TYPE  ID1  ID2  DATE
1998  4680     133    90    11    6    1    10061997
1999  4680     133    90    11    6    1    10021998 
1998  4680     133    90    11    8    2    10041997
1999  4680     133    90    11    8    2    10061998
1998  4772     133    44    11   10    1    11011997
1999  4772     133    44    11   10    1    11051998
1998  6407     133    44    11   23    7    10231997
1999  6407     133    44    11   23    7    10241998
1999  7371     133    44    11   24    1    11041997
2000  7371     133    44    11   24    1    11061999

You can use "by" function. It is used in grouping data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM