I am trying to replace NA values within the columns of a data frame, but since some columns have identical names the function dplyr::replace_na replaces the NAs only for the first occurrence of each column name.
library(dplyr)
library(stringr)
namesvec1<-c("John Smith","John Smith Jr df", "Luis Rivera","Ricardo Feliciano  ADE","Huber Villa Gomez 12","Christian Pilares","Luis Rivera","Luis Rivera","Christian Pilares") 
namesvec<-c("John Smith", "Ricardo Feliciano","Christian Pilares","Luis Rivera","John Smith Jr")
namesvec<-sort(namesvec,decreasing = T)
namesfun<-(sapply(namesvec1, function (x)(str_extract(x,sapply(namesvec, function (y)y)))))%>%as.data.frame(stringsAsFactors = F)
mylist<-list()
for(i in 1:ncol(namesfun)){
  mylist[i]<-"zzz"
}
names(mylist)<-names(namesfun)
replace_na(namesfun,mylist)
The result i get is this:

Am I doing something wrong?
 
     
     
    