Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201943

Join tables by ID and adding its to new column in dplyr

$
0
0

I have four differnet data frame by years (2015-2019), with variables: ID_patient(maybe duplicate), Treatment, date of start treatmen and date of end treatment and etc. (acctually it's 7 variables) Also I have data frame with 190 unique IDs from all years. So I want to add to my 190 unique IDs at data from dataframes by years 2015, 2016, 2017, 2018, 2019. For example: in 2015 I have 28 patients that recieved treatment, in 2016 - i have 148 patients. immportant to say, one patients may be duplicate in 2015 (other treatmetn but dates differents) and also its possible he recieved treatment in 2016. So I get expect 190 rows with unique IDs and columns from 2015-2019 years.
Here example data from 2015, row 8-10 same IDs:

 ID_Patient Name_code io    count_xrt first_xrt 
        <int> <chr>     <fct>     <int> <date>    
 1    1111111 Bone Pal~ Pemb~        12 2015-10-11
 2    2222222 SRS       Nivo~         2 2015-12-08
 3    3333333 Lung and~ Nivo~        19 2015-10-01
 4    4444444 Brain 3D  Clin~         5 2015-12-14
 5    5555555 Lung and~ Clin~         2 2015-10-04
 6    6666666 Bone Pal~ Pemb~         5 2015-10-01
 7    7777777 Lung and~ Nivo~        30 2015-10-25
 8   88888888 Bone Pal~ Nivo~         1 2015-10-12
 9   88888888 Soft Tis~ Nivo~         2 2015-12-16
10   88888888 Bone Pal~ Nivo~         2 2015-12-31
# ... with 18 more rows, and 2 more variables:
#   last_xrt <date>, io_start <date>

Here table with IDs:

A tibble: 190 x 1
   ID_Patient
        <dbl>
 1    1111111
 2    2222222
 3    3333333
 4    4444444
 5    5555555
 6    6666666
 7    7777777
 8    8888888
 9    9999999
10    12345678
# ... with 180 more rows

I was not successful with function "any"_join(maybe I'm just not doing it right)
So I want add data from 2015 to table with 190 unique IDs, for all 4 differnets tables. In general: I wan join 5 differnt tables by IDs, so finnaly for one IDs one row and many variables.


Viewing all articles
Browse latest Browse all 201943

Trending Articles