I was planning to make a new column with named vector which can match the names in dataframe, but it seems the matching is not done properly.
Here's an example code
vector <- c(APPLE=10,BANANA=2,KIWI=3,CARROT=4,ORANGE=5)
df <- data.frame(fru=c("APPLE","KIWI","CARROT","CARROT","KIWI","ORANGE","BANANA"))
df$num <- vector[df$fru]
in this code, the vector is defined like this,
APPLE BANANA KIWI CARROT ORANGE
1 2 3 4 5
but in the dataframe, the number corresponding to KIWI and CARROT doesn't match...
fru num
1 APPLE 10
2 KIWI 4
3 CARROT 3
4 CARROT 3
5 KIWI 4
6 ORANGE 5
7 BANANA 2
is there any misunderstanding in the way that i make indexing in vector?