I have a very simple problem. I have a large dataframe. And I need to replace values in a column 2 (cluster) following this schema:
1 -> 3
2 -> 5
3 -> 1
5 -> 2
> dput(head(df))
structure(list(Target = c("TRINITY_GG_100011_c0_g1_i3.mrna1",
"TRINITY_GG_100011_c0_g1_i5.mrna1", "TRINITY_GG_100011_c0_g1_i6.mrna1",
"TRINITY_GG_100011_c0_g1_i9.mrna1", "TRINITY_GG_100016_c0_g1_i1.mrna1",
"TRINITY_GG_100016_c0_g1_i2.mrna1"), cluster = c(2L, 5L, 5L,
3L, 4L, 5L), AAA = c(9L, 7L, 8L, 7L,
5L, 5L)), row.names = c(NA, 6L), class = "data.frame")
#normally I will do it like this:
df$cluster[df$cluster == 1] <- 3
The problem is that once I change 1 for 3, the next time I got to change 3 for 1 that will change it again. So I can't approach this sequentially. I need something that will use the original number and change them all at once.