So basically I have a column in a data frame like:
df <- data.frame(well = c("0","1",NA,"1","1","2","2","3","4","3"))
I just want to create a new column by replacing "0" to "A", "1" to "B",...,"7" to "H". I was trying this unsuccessfully:
lxn <- data.frame(old_name = c(0,1,2,3,4,5,6,7),
new_name = c("A","B","C","D","E","F","G","H"))
map <- lxn$new_name
names(map) <- lxn$old_name
df <- df %>% mutate(well_l = ifelse(well %in% names(map),
map[well],
well))
If you try it you can see that the output is basically the well number + 1. I do not know why I am not retrieving the letters (new_name) and getting the number of well + 1.
Hope someone can help me.
Aucun commentaire:
Enregistrer un commentaire