This is a test version of Biostars. For the public version, visit https://www.biostars.org.
R - Merging and aligning two CSVs using common values in multiple columns

I currently have two .csv files that look like this:

File 1:

enter image description here

File 2:

enter image description here

I would like to merge and align the two .csvs such that the result each row of File 1 is aligned by its "result" cell, against any of the three "outcome" columns in File 2, leaving blanks or "NA"s if there are no similarities.

Ideally, would look like this:

enter image description here

Any help would be very much appreciated.

csv r

Please don't post images of the data.

  1. Convert File 2 to long format and store all outcome values in a column titled Outcome.
  2. Join File 1 and long formatted File2 on Result (from File1) and Outcome ( from long formatted File2, a column in which all outcomes are stored)
  3. Convert output (from step2) from long format to wide format.
  4. Format table using packages such as kable

I have created a new post with the data now shown as code instead of images.

0 answers

No answers yet.

Log in to answer this question.