2
votes

I want to join two dataset together, one is a spatial polygon dataframe and another one is dataframe.

    library(raster) # Import raster package

        vn<-getData(name="GADM",country="Vietnam",level=1) # Get Vietnam administrative map from GADM 

        # A csv file 
        df<-read.csv("https://raw.githubusercontent.com/tuyenhavan/Statistics/Dataset/Poverty_Vietnam_2015.csv",sep=";")


        # There are two duplicates values in vn dataset and remove it as below

        vietnam<-vn # Make a copy

        vietnam<-vietnam[-33,]

        vietnam<-vietnam[-42,]

    # Joining two datasets together


            names(df)[1]<-"VARNAME_1" # Change the name of Province column in df to the same as vn


  mydf<-  inner_join(vietnam@data$VARNAME_1,df$VARNAME_1,by="VARNAME_1") # It did not work

After trying different ways around, I am hopeless. Please help

1

1 Answers

3
votes

The error message gives you a hint:

no applicable method for 'inner_join' applied to an object of class "character"

Just join the two data frames instead of the character vector and factor:

mydf <- inner_join(vietnam@data,df,by="VARNAME_1")

Or, if you want to retain the spatial object,

mydf <- sp::merge(vietnam, df, by="VARNAME_1", all=F)