library(tidyverse)
library(readr)
library(countrycode)
library(stringr)
B07 <- read_csv("Downloads/BorderData/BorderApprehension2007.csv")
B08 <- read_csv("Downloads/BorderData/BorderApprehension2008.csv")
B07[is.na(B07)] = 0
B08[is.na(B08)] = 0
# and so on...
B07$CITIZENSHIP <- str_to_title(B07$CITIZENSHIP)
B07$continent <- countrycode(sourcevar = B07[,"CITIZENSHIP"], origin = "country.name", destination = "continent")
I want to assign a continent instead of the names of countries, but I keep running into this error...
Error in countrycode(sourcevar = B07[, "CITIZENSHIP"], origin = "country.name", : sourcevar must be a character or numeric vector. This error often arises when users pass a tibble (e.g., from dplyr) instead of a column vector from a data.frame (i.e., my_tbl[, 2] vs. my_df[, 2] vs. my_tbl[2])
Here is an image of my data: