[R] How to merge 3 data frames by rownames?

Ana Marija @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com
Tue Nov 5 17:16:05 CET 2019


Hi,

I have 3 data frames like this:

> head(s11)
                      B_NoD
Ebfrl.7uOZfnjp_E7k 7.583709
ueQUrXd5FH554RlhZc 5.177791
0Uu3XrB6Bd14qoNeuc 4.680306
0t7nhVLii6tSAxtLhc 4.565023
fSUyR.vR7Xu0iR4nUU 2.885992
0Tm7hdRJxd9zoevPlA 2.866847
> head(s22)
                     B_DwoC
Ebfrl.7uOZfnjp_E7k 7.583709
ueQUrXd5FH554RlhZc 5.177791
0Uu3XrB6Bd14qoNeuc 4.680306
0t7nhVLii6tSAxtLhc 4.565023
fSUyR.vR7Xu0iR4nUU 2.885992
0Tm7hdRJxd9zoevPlA 2.866847
> head(s33)
                      B_DwC
Ebfrl.7uOZfnjp_E7k 7.583709
ueQUrXd5FH554RlhZc 5.177791
0Uu3XrB6Bd14qoNeuc 4.680306
0t7nhVLii6tSAxtLhc 4.565023
fSUyR.vR7Xu0iR4nUU 2.885992
0Tm7hdRJxd9zoevPlA 2.866847

I tried merging them using:

rn <- rownames(s11)
l <- list(s11, s22, s33)
allF <- l[[1]]
for(i in 2:length(l)) {
  dat <- merge(allF, l[[i]],  by= "row.names", all.x= F, all.y= F) [,-1]
  rownames(allF) <- rn
}

but my allF has only one column in results, while it would have all 3
from all 3 data frames:

> head(allF)
                      B_NoD
Ebfrl.7uOZfnjp_E7k 7.583709
ueQUrXd5FH554RlhZc 5.177791
0Uu3XrB6Bd14qoNeuc 4.680306
0t7nhVLii6tSAxtLhc 4.565023
fSUyR.vR7Xu0iR4nUU 2.885992
0Tm7hdRJxd9zoevPlA 2.866847

Please advise,
Ana



More information about the R-help mailing list