merge - Combine two columns in R -


how combine 2 columns , replace missing values in r?

let's have data.frame:

d = data.frame(a = c(1,na,3), b = c(1,2,na)) 

looks this

    b 1  1  1 2 na  2 3  3 na 

how this:

  c 1 1 2 2 3 3 

assuming 2 columns either have same values or 1 of them na

d = data.frame(a = c(1,na,3), b = c(1,2,na)) d[['c']] <- rowmeans(d, na.rm = true) d      b c 1  1  1 1 2 na  2 2 3  3 na 3 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -