r - Joining two data frames and filling down empty columns -


i have 2 data frames need join , fill down.

df1

x   mean    sd  se 1   33.61975308 25.97177258 4.998269963 4   37.21666665 23.65853598 4.553087373 9   27.62490196 23.46366812 3.285570716 5   31.655  13.65466442 2.492989239 6   38.38888889 15.00562282 3.536859218 8   34.22333333 18.45231005 3.551148725 20  32.05768194 19.09932561 2.465712333 211 22.94747986 18.46874547 2.326843217 12  19.97051999 18.11757894 2.282600393 3   18.85689296 18.64166165 2.447770094 14  16.18053903 16.16570095 2.03668688 

df2

n   mean2   sdsub   lci uci lci2    uci2    lci3    uci3 20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 

the third data frame needs join these , fill down df2

df3 desired

x   mean    sd  se  n   mean2   sdsub   lci uci lci2    uci2    lci3    uci3 1   33.61975308 25.97177258 4.998269963 20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 4   37.21666665 23.65853598 4.553087373 20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 9   27.62490196 23.46366812 3.285570716 20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 5   31.655  13.65466442 2.492989239 20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 6   38.38888889 15.00562282 3.536859218 20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 8   34.22333333 18.45231005 3.551148725 20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 20  32.05768194 19.09932561 2.465712333 20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 211 22.94747986 18.46874547 2.326843217 20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 12  19.97051999 18.11757894 2.282600393 20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 3   18.85689296 18.64166165 2.447770094 20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 14  16.18053903 16.16570095 2.03668688  20  32.53997604 20.63952369 29.91928986 35.16066221 30.38002506 34.69992702 30.75555216 34.32439992 

i've tried rbind(), join(), bind_rows(), or rbind_all() no avail. ideas?

cheers

a solution merge. create variable has same value by argument.

df1$i <- "a" df2$i <- "a" df3 <- merge(df1,df2,by="i") df3$i <- null  df3      x     mean       sd       se  n    mean2    sdsub      lci      uci     lci2     uci2     lci3    uci3 1    1 33.61975 25.97177 4.998270 20 32.53998 20.63952 29.91929 35.16066 30.38003 34.69993 30.75555 34.3244 2    4 37.21667 23.65854 4.553087 20 32.53998 20.63952 29.91929 35.16066 30.38003 34.69993 30.75555 34.3244 3    9 27.62490 23.46367 3.285571 20 32.53998 20.63952 29.91929 35.16066 30.38003 34.69993 30.75555 34.3244 4    5 31.65500 13.65466 2.492989 20 32.53998 20.63952 29.91929 35.16066 30.38003 34.69993 30.75555 34.3244 5    6 38.38889 15.00562 3.536859 20 32.53998 20.63952 29.91929 35.16066 30.38003 34.69993 30.75555 34.3244 6    8 34.22333 18.45231 3.551149 20 32.53998 20.63952 29.91929 35.16066 30.38003 34.69993 30.75555 34.3244 7   20 32.05768 19.09933 2.465712 20 32.53998 20.63952 29.91929 35.16066 30.38003 34.69993 30.75555 34.3244 8  211 22.94748 18.46875 2.326843 20 32.53998 20.63952 29.91929 35.16066 30.38003 34.69993 30.75555 34.3244 9   12 19.97052 18.11758 2.282600 20 32.53998 20.63952 29.91929 35.16066 30.38003 34.69993 30.75555 34.3244 10   3 18.85689 18.64166 2.447770 20 32.53998 20.63952 29.91929 35.16066 30.38003 34.69993 30.75555 34.3244 11  14 16.18054 16.16570 2.036687 20 32.53998 20.63952 29.91929 35.16066 30.38003 34.69993 30.75555 34.3244 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -