dataframe - Merging different data frames with different columns in R -


i tried following code:

library(ggplot2) library(dplyr) library(tidyr)  other <- read.table(text='phase year    v14 v15 other   2017    0.016488414 0.027183601 other   2016    0.016937669 0.016937669 other   2016    0.020214521 0.010313531 other   2016    0.025205761 0.099279835 other   2016    0.014341085 0.037596899 other   2016    0.01622807  0.04254386', header=true)   code <- read.table(text='phase   year    v5  v8  v19 v21 code    2017    0.016488414 0.053921569 0.01114082  0.027183601 code    2016    0.033197832 0.016937669 0.016937669 0.016937669', header=true)  test <- read.table(text='phase   year    v6  v11 v20 v22 test    2017    0.032531194 0.027183601 0.016488414 0.305258467 test    2016    0.106368564 0.025067751 0.016937669 0.025067751', header=true)  # tidy data code_df <- code %>%           gather(key, value, v5, v8, v19, v21) test_df <- test %>%           gather(key, value, v6, v11, v20, v22) other_df <- other %>%           gather(key, value, v14, v15)   newd <- merge(other_df, code_df, test_df, all=true) par(mfrow = c(1, 2)) ggplot(data=newd, aes(x=year)) +   geom_density(aes(group=phase, color=phase, fill=phase, showguide=false)) +   ggtitle("test")+   xlab("year")+   ylab("probability")+   facet_wrap(~phase, ncol=1) 

my results not promising, plot data set without loosing of them after merging, because want each data frame in separated graph, same in same frame. 1 have idea what wrong in code?

i think trying bind columns based on both phase , year. dplyr approach be.

library(dplyr)  df <- df1 %>%   bind_cols(df2, = c("phase", "year")) %>%   bind_cols(df3, = c("phase", "year")) 

edit

i see gather building long format, we'll switch bind_rows bring together.

newd <- bind_rows(other_df, code_df, test_df) 

your plot generate after changing line.

enter image description here


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -