I'm working with data that look like this:
| label |
|---|
| a |
| b |
| c |
I have a key-value index I've created (with code like that below) to use in creating a new column based on this existing column.
values <- c("word1", "word2", "word3")
keys <- c("a", "b", "c")
index <- setNames(as.list(values), keys)
With this index made, I was expecting to be able to create a new column with a simple one line for loop, like below.
df$newcol <- for (x in df$label){index$x}
This code doesn't seem to produce any change in my dataframe at all, though. What am I not understanding here?