Re: [R] Count cases in a list

2010-05-10 Thread Sebastian Kruk
I would like to obtain a matrix 2010/5/8 Tal Galili : > Here is one way for doing that: > nombreL <- c("Alvaro Perez", "Sebastian García","Sebastian 2", "Luis Gomez", > "Jorge Rial", "Ronaldo Apud", "Ana María Bianco") > nombreC <- c("Alvaro", "Ana","Jorge","Ronaldo", "Sebastian") > func1 <- funct

Re: [R] Count cases in a list

2010-05-08 Thread Tal Galili
Elegant Henrique, thanks ! Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---

Re: [R] Count cases in a list

2010-05-08 Thread Henrique Dallazuanna
Try this also: colSums(sapply(nombreC, grepl, nombreL)) On Sat, May 8, 2010 at 5:22 AM, Sebastian Kruk wrote: > 2010/5/8 Tal Galili : > > Hi Sebastian, > > Please check if this does what you want: > > > > nombreL <- c("Alvaro Perez", "Sebastián García", "Luis Gomez", "Jorge > Rial", > > "Ronald

Re: [R] Count cases in a list

2010-05-08 Thread Dennis Murphy
func2 <- function(x) which(grepl(x, noquote(nombreL))) lapply(noquote(nombreC), func2) Side note: if you wanted the object a in Tal's solution to be a vector, you could use sapply() rather than lapply(). For this problem, the solution has to be a list because the position matches are unequal in nu

Re: [R] Count cases in a list

2010-05-08 Thread Sebastian Kruk
One last thing, i want to know in which position was founded every name. 2010/5/8 Tal Galili : > There you go: > > nombreL <- c("Alvaro Perez", "Sebastian García","Sebastian 2", "Luis Gomez", > "Jorge Rial", "Ronaldo Apud", "Ana María Bianco") > nombreC <- c("Alvaro", "Ana","Jorge","Ronaldo", "Seb

Re: [R] Count cases in a list

2010-05-08 Thread Tal Galili
There you go: nombreL <- c("Alvaro Perez", "Sebastian García","Sebastian 2", "Luis Gomez", "Jorge Rial", "Ronaldo Apud", "Ana María Bianco") nombreC <- c("Alvaro", "Ana","Jorge","Ronaldo", "Sebastian") func1 <- function(x) { length(grep(x, noquote(nombreL))) } a <- lapply(noquote(nombreC), func1

Re: [R] Count cases in a list

2010-05-08 Thread Sebastian Kruk
2010/5/8 Tal Galili : > Hi Sebastian, > Please check if this does what you want: > > 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") > func1 <- function(x) > { > grep(x,

Re: [R] Count cases in a list

2010-05-08 Thread Tal Galili
Hi Sebastian, Please check if this does what you want: 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") func1 <- function(x) { grep(x, noquote(nombreL)) } lapply(noquote(n

Re: [R] Count cases in a list

2010-05-08 Thread Sebastian Kruk
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(no

Re: [R] Count cases in a list

2010-05-08 Thread Tal Galili
Hi Sebastian, Please add an example to the code you made, so to make it easier to help you. p.s: it seems possible to make it faster using lapply Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read

[R] Count cases in a list

2010-05-08 Thread Sebastian Kruk
Hi everybody, I would like to count how many times names in list L, nombreL, apear in list C, nombreC. Can I improve the next program? cuenta <- 0 topL <- length(nombreL) topC <- length(nombreC) for (i in 1:topL) { for (j in 1:topC) {