0

I have hundreds of dataframes whose names end either with "_flow" or "_rain", and I would like to rbind them all into two dataframes – one for flow data and one for rain data.

I guess the equivalent of this in Linux would be:

cat *_flow.csv >> flow.csv
cat *_rain.csv >> rain.csv

How do I do this in R?

  • 1
    Something like `all_flow <- do.call("rbind", mget(ls(pattern="flow")))` should work – MrFlick Feb 19 '21 at 19:23
  • Lots of ways to do this, but if you had imported all your flow dataframes into a list, you could combine them all row-wise with Reduce(flowList, rbind) – Bill O'Brien Feb 19 '21 at 20:20

1 Answers1

1

Here is one way to find the files and rbind them:

files <- grep("_flow|_rain", dir(), value = TRUE)
  
library(vroom)

data <- vroom(files)
stevec
  • 41,291
  • 27
  • 223
  • 311