如何合并数据框与对象名称中的匹配字符?

How do I merge data frames with matching characters in the object name?

我有一堆单独的数据框,它们的名称如 day01_01_1of2day01_01_2of2day01_02_1of2

我想创建一个条件语句,它将找到第一个字符匹配的数据帧(即 day01_01)并将行绑定在一起。我找不到任何方法来做到这一点。

我可以在 R 中操作列表中的数据: Image of the lists from Rstudio

或来自全球环境中的单个数据帧

ls()
 [1] "day01_01_1of2" "day01_01_2of2" "day01_02_1of2" "day01_02_2of2" "day01_03_1of2"
 [6] "day01_03_2of2" "day01_04_1of2" "day01_04_2of2" "day01_05_1of2" "day01_05_2of2"
[11] "day01_06_1of2" "day01_06_2of2" "day01_07_1of2" "day01_07_2of2" "day01_08_1of2"
[16] "day01_08_2of2" "day01_09_1of2" "day01_09_2of2" "day01_10_1of2" "day01_10_2of2"

我正在寻找列表中或列表外的任何解决方案。

感谢您提供的任何帮助。

我们可以用向量的子串分割向量

str1 <- ls()
lst1 <- split(str1, sub("_[^_]+$", "", str1))
lst2 <- lapply(lst1, function(x) do.call(rbind, mget(x, inherits = TRUE)))