I am trying to revalue the data points for one of the variables in the dataset I am working with.
The variable assigns race. Instead of listing out the race as the data point, it is a number. I am trying the revalue the number so that it states the corresponding race.
library(plyr)
as.character(data$MRACEHISP)
nat2015p01_new2020$mothersrace <- revalue(data$MRACEHISP, c("1"="WHITE", "2" = "BLACK", "3" = "AIAN", "4"="ASIAN", "5" = "NHOPI", "6" = "MULTIPLE", "7" = "HISPANICE", "8" = "OTHER" ))
I keep getting the following error: Error in revalue(nat2015p01_new2020$MRACEHISP, c( 1
= "WHITE", 2
= "BLACK", : x is not a factor or a character vector.
I am unsure how to solve this error and go about the problem. Any help would be appreciated. Thanks!
You need to store the character values in data
library(plyr)
data$MRACEHISP <- as.character(data$MRACEHISP)
nat2015p01_new2020$mothersrace <- revalue(data$MRACEHISP, c("1"="WHITE", "2" = "BLACK", "3" = "AIAN", "4"="ASIAN", "5" = "NHOPI", "6" = "MULTIPLE", "7" = "HISPANICE", "8" = "OTHER" ))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.