title: How to replace NAs of a variable with values from another dataframe
body: <p>i hope this one isn´t stupid.</p>
  
  <p>I have two dataframes with Variables ID and gender/sex. In df1, there are NAs. In df2, the variable is complete. I want to complete the column in df1 with the values from df2.
  (In df1 the variable is called "gender". In df2 it is called "sex".)</p>
  
  <p>Here is what i tried so far:</p>
  
  <pre><code>#example-data
  ID&lt;-seq(1,30,by=1)
  df1&lt;-as.data.frame(ID)
  df2&lt;-df1
  df1$gender&lt;-c(NA,"2","1",NA,"2","2","2","2","2","2",NA,"2","1","1",NA,"2","2","2","2","2","1","2","2",NA,"2","2","2","2","2",NA)
  df2$sex&lt;-c("2","2","1","2","2","2","2","2","2","2","2","2","1","1","2","2","2","2","2","2","1","2","2","2","2","2","2","2","2","2")
  
  
  #Approach 1: 
  NAs.a &lt;- is.na(df1$gender)
  df1$gender[NAs.a] &lt;- df2[match(df1$ID[NAs.a], df2$ID),]$sex
  
  #Approach 2 (i like dplyr a lot, perhaps there´s a way to use it):
  library("dplyr")
  temp&lt;-df2 %&gt;% select(ID,gender)
  
  #EDIT:
  #df&lt;-left_join(df1$gender,df2$gender, by="ID") 
   df&lt;-left_join(df1,df2, by="ID") 
  </code></pre>
  
  <p>Thank you very much.</p>