creating a new column from recoding a column in a data frame

We don't have the data, and you didn't tell us what the errors are, so it's hard to help. Could you provide a minimal reproducible example, as described here: