Bee Bee - 1 month ago 14
R Question

Error calling gender in dataframe

I have a data frame of names which I read from a csv file. contents of the data frame is as below.

NAME CURR_GENDER COUNT
1 LESLIE N 186
2 COREY N 86
3 KELSEY N 52
4 DARYL N 38
5 PRISCIANDARO N 33
6 SUNG N 30


I am trying to determine the gender using gender library given the name and add the output as a column to the existing data frame.

csv_in <- "Names.csv"

Names_df <- read.csv(csv_in)

gender(Names_df$NAME,
method = "ssa",
years = c(1930, 2012)) %>%
do.call(rbind.data.frame, .)


However, I am getting the below error. Hoping you can point out what I am doing wrong here.


Error in gender(Names_df$NAME, method = "ssa", years = c(1930, 2012))
: Data must be a character vector.

Answer

The error is telling you that Names_df$NAME is not a character vector, but needs to be. Try running

Names_df$NAME <- as.character(Names_df$NAME) 

and then trying again. If that doesn't work, run class(Names_df$NAME) and tell us what comes up.