I'm attempting to rename the level A
of factor column1
in the dataframe df
in R. My current approach is this:
levels(df[!is.na(df$column1) & df$column1 == 'A',]) <- 'B'
which doesn't throw any errors or warnings but is completely ineffective.
B
is not an already existing level (which from trial and error I came to suspect was important), so the following, my first attempt, didn't work either
df[!is.na(df$column1) & df$column1 == 'A', 'column1'] <- 'B'
Could anyone guide me to the correct approach?