I am trying to loop through the values within a categorical variable and assign a number based on whether the value is "yes" or "no"
My data is "train" and the variable is "default" which looks as follow:
default = c("no", "yes", "no"....)
I want to create a separate vector which contains thee number 10 for any value of "yes" and the number 1 for nay value "no."
I tried:
wgts = c()
for (y in 1:nrow(train)) {
ifelse(train$default[y] == "yes", wgts = append(wgts[y], 10), wgts = append(wgts[y], 1))
return(wgts)
}
But the resulting vector is turning out to be NULL. How can I fix this?