. @Procrastinatus Maximus
df1$rn <- rownames(df1)
df2$rn <- rownames(df2)
melt(list(df1, df2), id.vars = "rn")
Then we use the dcast function with the mget function, which is used to extract multiple variables at once.
mydf<- dcast(melt(mget(ls(pattern = "df\\d+")), id.vars = "rn"),
rn ~ variable, value.var = "value", fun.aggregate = sum)
rownames(mydf) <- mydf$rn
mydf <- mydf[, -1]
> mydf
source
share