I want to change the character "F" to "X" in a dataframe. Please see below.
df <- data.frame(N=c(1,2,3,4,5,6),CAT=c('A','B','C','D','E','F'))
df
Result:
N CAT
1 1 A
2 2 B
3 3 C
4 4 D
5 5 E
6 6 F
I've run this code and it doesn't work
df$CAT[df$CAT == 'F'] <- 'X'
Error in `$<-.data.frame`(`*tmp*`, code, value = character(0)) :
replacement has 0 rows, data has 6
This code seems to work on other data I've imported via csv. Is there a reason why it doesn't work with this specific dataframe I've created? Any help much appreciated.