Hi everyone - firstly, please excuse any amateurish language. I am an amateur.
I am trying to merge a .csv file onto a shapefile in R. Essentially I want to create a map of London showing crime rates at the ward level for a research project. To do this, I have a MSOA map downloaded from London Datastore (I have used this file before and it has always worked fine) and a manipulated crime rate csv file, with two columns, one with the ward code (matches to the shapefile) and one with the number of crimes. I'm only able to put one image in so I have only got a screenshot of the merged data below!
When I merge together using the code below, the files merge fine, but I lose all the data in the crime column, and it just comes up as a list of 'NA' rather than the numbers. I have tried changing the column type from double to integer to numeric etc. to see if this would help and it didn't. I also tried opening up the file in a new directory to check it wasn't just a bug, and this didn't help either. As I say, I have done very similar operations before with this shapefile, and have never had this issue come up.
Here's the code I used to open the files and merge together:
library(rgdal)
library(rgeos)
library(tmap)
library(sp)
library(dplyr)
##Unecessary packages are for use later in the project
Let shp be your MSOA shapefile, coerced into a dataframe with an area identifier and the boundries. Let dat be your csv file imported into a dataframe with an area identifier corresponding. Then