merge all data in global environment

Hello everyone,

I have a long list of dataframes in my global environment, each dataframe has two columns; "date" and "value"

#example dataframes:

AMSTE01
datum                    AMSTE01
2020-06-09 11:30:00      26,21
2020-06-09 11:40:00      19,09

AMSTE02
datum                    AMSTE02
2020-06-08 14:00:00      18,02
2020-06-08 14:10:00      17,80
2020-06-09 11:30:00      19,23

I would like to merge all data in the environment to get something like this:

ALL_DATA
datum                    AMSTE02        AMSTE01
2020-06-08 14:00:00      18,02
2020-06-08 14:10:00      17,80     
2020-06-09 11:30:00      19,23           26,21
2020-06-09 11:40:00                      19,09

I have a total of about 70 dataframes which I would like to merge all together like this

I have no idea how to do this.

Thanks in advance

I think this does what you're looking for:

library(tidyverse)

# Create some data frames
a <- data.frame(date = 1:2, value1 = rnorm(2))
b <- data.frame(date = 2:4, value2 = rnorm(3))

# Find only data.frames in global env
objs <- mget(ls(envir = globalenv()))
dfs <- objs[map_lgl(objs, is.data.frame)]

merged <- reduce(dfs, full_join)
#> Joining, by = "date"
merged
#>   date     value1    value2
#> 1    1 -0.4681070        NA
#> 2    2  0.7094147 -1.601239
#> 3    3         NA -1.095174
#>  [ reached 'max' / getOption("max.print") -- omitted 1 rows ]
3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.