r - Compare values of two dataframes and substitute them -


i've 2 data frames same number of rows , columns, 113x159 structure:

df1:

   1  2  3  4 @ aa ag ct b na ag @ cc c ag gg gt aa d na na tt tc 

df2:

   1  2  3  4 na 23 12 na b na 23 44 12 c 11 14 27 55 d na na 12 34 

i want compare value value db1 e db2, , if value of db 2 na , value of db1 isn't, replace (also if db1 value na , in db2 not). @ end, df has this:

   1  2  3  4 na aa ag na b na ag @ cc c ag gg gt aa d na na tt cc 

i've written if loop doesn't work:

merge.na<-function(x){ (i in df2) , (k in df1){     if (i==na) , (k!=na)     k==na} 

any idea?

we can use replace

replace(df1, is.na(df2), na) #   x1   x2 x3   x4 #a <na>   aa ag <na> #b <na>   ag @   cc #c   ag   gg gt   aa #d <na> <na> tt   tc 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -