r - How to compare 2 vectors element by element using loop -
i'm trying compare elements 2 vectors in way,but result first element.
>ex1<-c('gdgdg','dd','fffff','ssdsds') fuct1<-function(x){ for(i in 1:length(x)){ ex2<-c('xxxx','ddd','ddd','ddd','dddd') match<-agrep(x[i],ex2[i],value='true') return(match[i]) } } >fuct1(ex1)
by example want compare 'gdgdg' , 'xxxx'(first elements each vector) 'dd'and 'ddd'(second ones) , on...,as result have (na,ddd,na,na). result code na. help.
t think looking mapply
mapply(agrep,ex1,ex2,value=true)
but assume 2 vectors have same length.
Comments
Post a Comment