dataframe - Merge Two df with different number of columns with R -


this question has answer here:

i have 2 dataframes, have overlapping set of columns unique columns too.

they contain of same observations.

to give concrete example:

df1 <- data.frame(name = c("a", "b", "c", "d"),                 age = c(1:4),                 party = c(3:6) )       df2 <- data.frame(name = c("a", "e", "c", "f"),                other = c(10:13),                party = c(3:6) )  

both dfs contain observations a , c

how merge dfs create new df contains columns, not repeat observations?

you can use merge() base r.

merge(df1, df2, all=t) # name party age other # 1        3   1    10 # 2    b     4   2    na # 3    c     5   3    12 # 4    d     6   4    na # 5    e     4  na    11 # 6    f     6  na    13 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -