From what I can tell, sf() merge doesn't support comparison operations by.x etc. Is there a feasible way to mesh two data sets, one of which is a simplefeature and the other a basic table from CSV or xlsx?
Example, to give a sense of what I mean. I could do something like this with a spatial dataframe generated by sp():
admin_lev1 <- merge(x=admin_lev1, y=admin_lev1_pop, by.x = "code", by.y = "CODE")
and I would end up with a pleasantly aggregated dataframe. I've mangled around with sf() and it seems like this functionality - to specify by.x and by.y isn't in place and can't be reproduced.
Data for reproducible example:
admin_lev1_pop.csv:
council areas,2011_pop,code
Aberdeen City,"222,793",S12000033
Aberdeenshire,"252,973",S12000034
Angus,"115,978",S12000041
Argyll & Bute,"88,166",S12000035
Clackmannanshire,"51,442",S12000005
Dumfries & Galloway,"151,324",S12000006
Dundee City,"147,268",S12000042
East Ayrshire,"122,767",S12000008
East Dunbartonshire,"105,026",S12000045
East Lothian,"99,717",S12000010
East Renfrewshire,"90,574",S12000011
"Edinburgh, City of","476,626",S12000036
Eilean Siar,"27,684",S12000013
Falkirk,"155,990",S12000014
Fife,"365,198",S12000015
Glasgow City,"593,245",S12000046
Highland,"232,132",S12000017
Inverclyde,"81,485",S12000018
Midlothian,"83,187",S12000019
Moray,"93,295",S12000020
North Ayrshire,"138,146",S12000021
North Lanarkshire,"337,727",S12000044
Orkney Islands,"21,349",S12000023
Perth & Kinross,"146,652",S12000024
Renfrewshire,"174,908",S12000038
Scottish Borders,"113,870",S12000026
Shetland Islands,"23,167",S12000027
South Ayrshire,"112,799",S12000028
South Lanarkshire,"313,830",S12000029
Stirling,"90,247",S12000030
West Dunbartonshire,"90,720",S12000039
West Lothian,"175,118",S12000040
download.file("https://borders.ukdataservice.ac.uk/ukborders/easy_download/prebuilt/shape/Scotland_ca_2010.zip",
destfile = "data/Scotland_ca_2010.zip")
unzip("data/Scotland_ca_2010.zip", exdir = "data")
admin_lev1 <- st_read("data/scotland_ca_2010.shp") %>% st_transform(27700)
Ideally, what I need to do is join admin_lev1_pop
data in the column 2011_pop
to admin_lev1
but I'm at a loss as to how to accomplish this using the new feature set in sf().
merge
is supported onsf
, check an example here dieghernan.github.io/cartographyvignette linecntries = merge(cntries, df, by.x = "ISO3_CODE", by.y = "ISO_3166_3", all.x = TRUE)
dplyr::left_join