For example if nombreC <- nombreC <- c("Juan", "Carlos", "Ana", "María","Mario")
I do not want as a result: name index 1 Juan 1 2 Juan 5 3 Carlos 2 4 Ana 3 5 María 4 6 Mario 0 I want: name index 1 Juan 1 2 Juan 5 3 Carlos 2 4 Ana 3 5 María 4 As an result of the do.call I want a data frame where every name has an index > 0. 2010/5/16 <markle...@verizon.net>: > Hi Sebastian: I'm not sure that I understand what you want but maybe below > is what you want ? I just took out the nummatches > column. > > > nombreC <- c("Juan", "Carlos", "Ana", "María") > nombreL <- c("Juan Campo", "Carlos Gallardo", "Ana Iglesias", "María > Bacaldi", "Juan Grondona", "Dario Grandineti", "Jaime Acosta", > "Lourdes Serrano") > > do.call(rbind,lapply(nombreC,function(.name) { > index <- grep(.name,nombreL) > nummatches <- if (length(index) > 0) length(index) else 0 > index <- if( length(index) > 0) index else 0 > # data.frame(name=.name,index=index,nummatches=nummatches) > data.frame(name=.name,index=index) > })) ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.