add different data frames based on column names

0

I really need your help to complete an analysis. I have the following tables (data frames):

df1<-data.frame(c(0,1,1,0),c(1,0,0,1),c(1,1,0,0))
colnames(df1)<-c("0","0.5","1")
df2<-data.frame(c(1,1,1,0),c(0,1,0,0))
colnames(df2)<-c("0","0.5")
df3<-data.frame(c(1,1,1,1),c(0,0,0,1))
colnames(df3)<-c("0.5","1")

understand that for the analysis to work I need all three tables to have the columns 0, 0.5 and 1. I thought of adding up all the tables with a template table containing the three columns and values all equal to zero, but I still could not figure it out. Do you think this is the solution? How can I do this? Thank you guys !!

    
asked by anonymous 26.12.2017 / 19:03

1 answer

2

Sorry guys, it was really easy

molde<-data.frame(c(0,0,0,0),c(0,0,0,0),c(0,0,0,0))
colnames(molde)<-c("0","0.5","1")

melted <- cbind(df2,molde)
aggr <- as.data.frame(do.call(cbind, by(t(melted),INDICES=names(melted),FUN=colSums)))

Thank you anyway

    
26.12.2017 / 19:17