1

I'm looking to use rbind to combine the SPDFs of different European countries. However, I'm looking to use SPDFs of different levels of regions. Unfortunately, I'm getting the following error:

library(sp)
library(raster)

France_map <- getData(name = "GADM", country = "FRA", level = 0)
Germany_map <- getData(name = "GADM", country = "DEU", level = 1)
Belgium_map <- getData(name = "GADM", country = "BEL", level = 2)

test <- rbind(France_map, Germany_map, Belgium_map, makeUniqueIDs = TRUE)

Error in rbind(deparse.level, ...) : 
  numbers of columns of arguments do not match

How do I need to treat the individual SPDFs so that they can be bound together?

1
  • 1
    dplyr::bind_rows() works for the SPDF@data not having the same columns, but not for the whole SPDF, you may try to do that as two separate tasks
    – Elio Diaz
    Jan 8, 2018 at 18:45

2 Answers 2

1

The attributes/columns in each dataframe are completely different, but if you want to bind with rbind they need to match.

Is there a reason for the different administrative levels? If you were to use (e.g.) level=1 for each country, the attributes would match and the rbind will work as intended.

If you need to keep the specified levels, then you'll need to reduce and harmonise the attributes/columns before attempting the rbind.

1
  • Thanks Jul. I have since manually harmonized the columns across the SPDFs, and they now work fine.
    – Phil
    Jan 9, 2018 at 0:47
1

There is no actual need for a two-step approach when trying to combine the single objects in such a way that all columns are kept (ie. missing columns are filled with NA). In fact, this can be achieved in one go using bind() from raster:

out1 = bind(France_map, Germany_map, Belgium_map)

# or, when dealing with lists (eg. resulting from some *apply call),
countries = list(France_map, Germany_map, Belgium_map)
out2 = do.call(bind, countries)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.