0

I have three sets of data tables with different sets of columns. The locationNames.xxx variables have the data set names with common columns.

locationNames.complete <- c("BangsCanyon", "BookCliffs", "Escalante", "Highline", "Ute")
locationNames.noWind <- c("DougPass", "GrandMesa")
locationNames.noT <- c("Palisade", "Pitkin", "Whitewater")

And a variable that has all the data set names.

allSites <- c(locationNames.complete, locationNames.noWind, locationNames.noT)

I do some manipulation on each of these, including a common date column formatted as POSIXct. I want to merge them all together into one combined file on date.

I know about the following approach to merge multiple data sets where the list has the data table names, without quotes.

combined.sites.1 <- Reduce(merge,list(BangsCanyon, BookCliffs, Escalante))

But none of the following approaches work, presumably because the locationNames variables are character.

combined.sites.2 <- Reduce(merge,list(locationNames.complete, locationNames.noWind, locationNames.noT))
combined.sites.2 <- Reduce(merge,list(allSites))
combined.sites.2 <- Reduce(merge,list(get(allSites)))

The last of these three gives a data table that has columns from only the first data table in the allSites variable. I suspect there is something obvious I'm missing.

JerryN
  • 2,356
  • 1
  • 15
  • 49

1 Answers1

2

I think this should work:

combined.sites <- Reduce(merge,lapply(allSites,get))

Let me know if it doesn't.

A Gore
  • 1,870
  • 2
  • 15
  • 26
  • It does, but... I'd also like to be able to use all = TRUE as well. The following doesn't work. combined.sites.test <- Reduce(merge,lapply(allSites,get), all = TRUE) – JerryN Jun 28 '17 at 19:21
  • 1
    @JerryN Here's a solution to pass multiple arguments to Reduce function https://stackoverflow.com/questions/34954811/using-reduce-to-merge-multiple-data-frames-with-passing-arguments-and-without-de – A Gore Jun 28 '17 at 20:53