r code in R snippet 2:1 doesn't produce same results as R

I try to change values on a dataframe column based on excel file so i used R snippet 2:1

R code

 

kIn1<-dat
kIn2<-Values
y<-"RegionCode8"

library(zoo)
kIn2$Value<-na.locf(kIn2$Value)
values<-sort(unique(kIn1[,y]))
for(i in 1:length(values)){
  kIn1[kIn1[!is.na(kIn1[,y]),y]==values[i],y]<-kIn2$Label[kIn2$Value==y][i]
}
rOut<-kIn1

output:

> unique(kIn1$RegionCode8)
[1] "East Asia"                           "Western Europe & Israel"            
[3] "South Asia"                          "Eastern Europe, Russia & Former CIS"
[5] "North America"                       "Middle East & Africa"               
[7] "South America"                       "Oceania"                            

 

R snippet code 

y<-'RegionCode8'

kIn1$RegionCode8<-as.character(kIn1$RegionCode8)
library(zoo)
kIn2$Value<-na.locf(kIn2$Value)
values<-sort(unique(kIn1[,y]))
for(i in 1:length(values)){
  kIn1[kIn1[!is.na(kIn1[,y]),y]==values[i],y]<-kIn2$Label[kIn2$Value==y][i]
}
rOut<-kIn1

output: NA and some initial numbers

Please help

Hi there, This is using the Community Scripting integration, and the question is probably best asked in the community part of the forum: https://www.knime.com/forum/scripting-integrations