So my data is currently split into 211 dataframes in R and I was wondering if there was a way to combine all of them without having to type out the name of every dataframe. Each dataframe is named in a similar way: starts with "dma" then has the number of the dma it corresponds to (dma1-dma211). Is there a combine/merge function that allows me to select all dataframes that start with "dma" and combine them? All of the dataframes have the same columns and names of columns and I want to combine them vertically. Thanks!!
We can use mget
to get the values of the objects that starts with 'dma' followed by digits into a list
and then rbind
with do.call
in base R
out <- do.call(rbind, mget(ls(patterns = '^dma\\d+$')))
Or with tidyverse
library(dplyr)
out <- mget(ls(patterns = '^dma\\d+$')) %>%
bind_rows
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.