[R] Count cases in a list

Sebastian Kruk residuo.solow at gmail.com
Sat May 8 09:46:32 CEST 2010


Hi, for example I have two list:

nombreL <- c("Alvaro Perez", "Sebastián García", "Luis Gomez", "Jorge
Rial", "Ronaldo Apud",..., "Ana María Bianco")
nombreC <- c("Alvaro",..., "Ana",...,"Jorge",...,"Ronaldo", "Sebastian",...)

and my code is:

cuenta <- 0
topL <- length(nombreL)
topC <- length(nombreC)
for (i in 1:topL) {
                     for (j in 1:topC) {
                                           k <-
grep(noquote(nombreL[i]),nombreC[j])
                                           if (length(k) > 0){

cuenta <- cuenta + 1
                                            }
                      }

Thanks,

Sebastian.



More information about the R-help mailing list