Combine a list of data frames into one preserving row names

99封情书 提交于 2019-12-01 16:23:10

To preserve rownames, you can simply do:

do.call(rbind, unname(l))

#  x
#a 1
#b 2
#c 3
#d 4
#e 5
#f 6
#g 7
#h 8
#i 9

Or as you underlined by setting the rownames of l to NULL , this can be also done by:

do.call(rbind, setNames(l, NULL))

We can use add_rownames from dplyr package before binding:

rbind_all(lapply(l, add_rownames))

# Source: local data frame [9 x 2]
#
#   rowname x
# 1       a 1
# 2       b 2
# 3       c 3
# 4       d 4
# 5       e 5
# 6       f 6
# 7       g 7
# 8       h 8
# 9       i 9

Why not only using rbind:

 rbind(l$A, l$B, l$C)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!