Q:

How to create categorical variables from text values in R

I have a data set with a categorical variable Weather. This variable has 3 different text values i.e. "Dry", "Drizzle" and "Rain".
I want to create another variable to which I can assign numeric values for these variables. For example Dry will be 1, Drizzle will be 2 and Rain will be 3.
As a side information, the weather variable will be used to predict blockage in water systems, so I will use this in some sort of linear regression model. 

A:

We can convert to factor and then coerce to integer
as.integer(factor(df1$Weather, levels = c("Dry", "Drizzle", "Rain"))

A:

For the record, this would also do the job:
match(df1$Weather, c("Dry", "Drizzle", "Rain"))

This is slightly faster than @akrun's solution (already really fast anyway):
x <- sample(c("Dry", "Drizzle", "Rain"), 1e6, rep=T)

microbenchmark::microbenchmark(
   as.integer(factor(x, levels = c("Dry", "Drizzle", "Rain"))),
   match(x, c("Dry", "Drizzle", "Rain"))
)

Unit: milliseconds
expr      min       lq       mean     median       
14.31158  18.13069  23.19702 20.98414 23.10840 
13.30326  16.00538  19.07544 17.59751 19.53679  

