-1

enter image description here

I web scraped 50 states from a website and added them to my data set under the name "state_name", I need to correspond all the state values 1 with Alabama all state values 2 with Alaska, etc...

2 Answers2

0
df$state_value = as.factor(df$state_name)
aashish
  • 305
  • 1
  • 7
0

You can try

df$state_value <- as.integer(factor(df$state_name))

or

df$state_value <- match(df$state_name,unique(df$state_name))
ThomasIsCoding
  • 80,151
  • 7
  • 17
  • 65