Reputation: 69
Suppose I have three datasets
DF1=
Traj X Y
1 4 5
1 7 8
2 5 6
DF2=
Traj X Y
1 5 2
1 6 4
2 8 7
DF3=
Traj X Y
1 8 5
1 1 9
2 3 7
How can I combine them into one dataset like below:
DF1=
Traj X Y
1 4 5
1 7 8
2 5 6
1 5 2
1 6 4
2 8 7
1 8 5
1 1 9
2 3 7
I have many similar data that have similar elements and it would be easier to just combine them, unfortunately I don't know how to do so.
Upvotes: 2
Views: 91
Reputation: 226152
In base R, rbind(DF1, DF2, DF3
(rbind
stands for "row bind", i.e. "put rows together"). In tidyverse, dplyr::bind_rows(DF1, DF2, DF3)
is slightly fancier.
If you already have a list of your data frames,
DFlist <- list(DF1, DF2, DF3)
do.call(DFlist, rbind)
Upvotes: 3
Reputation: 887048
Another option is to place it in a list
and use bind_rows
library(dplyr)
mget(ls(pattern = '^DF\\d+$')) %>%
bind_rows
Upvotes: 2