title: How to replace specific rows based on conditions of another dataset in R
body: <p>I have have 2 genetic datasets which look like:</p>
  
  <p>dataset1:</p>
  
  <pre><code>ID          Chr Ref Alt
  1:10000476  NA  NA  NA
  1:10081736  NA  NA  NA
  1:100829685 NA  NA  NA
  1:100829720 NA  NA  NA
  10:1008338  NA  NA  NA
  </code></pre>
  
  <p>dataset2:</p>
  
  <pre><code>ID          Chr Ref Alt
  1:10000476  1   A   T
  1:10081736  1   C   G
  2:133248    2   A   T
  3:300829720 3   A   T
  10:1008338  10  A   T
  </code></pre>
  
  <p>I am trying to replace any NA's in dataset 1 with the data from dataset 2 if they have the same ID </p>
  
  <p>Trying to output:</p>
  
  <pre><code>ID          Chr Ref Alt
  1:10000476  1   A   T
  1:10081736  1   C   G
  1:100829685 NA  NA  NA
  1:100829720 NA  NA  NA
  10:1008338  10  A   T
  
  #first 2 rows have their NAs replaced with the data in the 2nd dataset, as the IDs match
  </code></pre>
  
  <p>I have a biology background, so haven't been sure where to start with this, my datasets also have many more columns. So far I have tried using <code>merge(df1, df2, by='ID', all.x=TRUE)</code>, but this is creating 2 versions of the columns with '.x' and '.y' - it looks like I could just take the columns with '.y' but I'm not sure why this is appearing in the first place and can't find information to know if I can trust it. Any help in the right direction would be appreciated.</p>
  
  <p>Input data:</p>
  
  <pre><code>#dataset1
  dput(df1)
  structure(list(ID = c("1:10000476", "1:10081736", "1:100829685", 
  "1:100829720", "1:100833868"), Chr = c(NA, NA, NA, NA, NA), Ref = c(NA, 
  NA, NA, NA, NA), Alt = c(NA, NA, NA, NA, NA)), row.names = c(NA, 
  -5L), class = c("data.table", "data.frame"))
  
  #dataset2
  dput(df2)
  structure(list(ID = c("1:10000476", "1:10081736", "2:133248", 
  "3:300829720", "4:5543348"), Chr = c(1L, 1L, 2L, 3L, 4L), Ref = c("A", 
  "C", "A", "A", "A"), Alt = c("T", "G", "T", "T", "T")), row.names = c(NA, 
  -5L), class = c("data.table", "data.frame"))
  </code></pre>