My dataframe has a column called "LandType" of characters, either "Rural" or "Urban" for a bunch of samples. All I want to do is convert them to 1's and 0's, where "Rural" is 1, and "Urban" is 0.
I thought it would as simple as:
data$LandType[data$LandType == "Rural"] <- 1
data$LandType[data$LandType == "Urban"] <- 0
But after running this with no errors and then checking my data df, the crazy thing is that ONLY "Rural" has changed to 1's but Urban still remains as a string. I tried with different numbers but same thing happened, only Rural would change to the value I assigned.
Urbanis written different indata$Landtype? Check it e.g. withtable(data$Landtype)orunique(data$Landtype)."Rural"and"Urban", and there are 72 "Rural" and 93 "Urban" samples.is.factor(data$Landtype)givesFALSE?LandTypethe other timeLandtype.