[R] Count cases in a list

Sebastian Kruk residuo.solow at gmail.com
Tue May 11 01:18:02 CEST 2010


I would like to obtain a matrix

2010/5/8 Tal Galili <tal.galili en gmail.com>:
> 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 <- function(x)
> {
> list(times = length(grep(x, noquote(nombreL))), where = (grep(x,
> noquote(nombreL))))
> }
> a <- lapply(noquote(nombreC), func1)
> names(a) <- nombreC
> a
>
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: Tal.Galili en gmail.com |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
> ----------------------------------------------------------------------------------------------
>
>
>
>
> On Sat, May 8, 2010 at 11:57 AM, Sebastian Kruk <residuo.solow en gmail.com>
> wrote:
>>
>> One last thing, i want to know in which position was founded every name.
>>
>> 2010/5/8 Tal Galili <tal.galili en gmail.com>:
>> > 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)
>> > names(a) <- nombreC
>> > a
>> >
>> >
>> >
>> >
>> > ----------------Contact
>> > Details:-------------------------------------------------------
>> > Contact me: Tal.Galili en gmail.com |  972-52-7275845
>> > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>> > www.r-statistics.com (English)
>> >
>> > ----------------------------------------------------------------------------------------------
>> >
>> >
>> >
>> >
>> > On Sat, May 8, 2010 at 11:22 AM, Sebastian Kruk
>> > <residuo.solow en gmail.com>
>> > wrote:
>> >>
>> >> 2010/5/8 Tal Galili <tal.galili en gmail.com>:
>> >> > 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(nombreC), func1)
>> >>
>> >> Hi Tal, I just want to count how many time appear any element of
>> >> nombreC in nombreL.
>> >>
>> >> Alvaro appear once in nombreL so cuenta = 1
>> >> Ana appear 0 times in nombreL so cuenta = 1
>> >> Jorge appear 0 times in nombreL so cuenta = 1
>> >> Ronaldo appear 0 times in nombreL so cuenta = 1
>> >> Sebastian appear once in nombreL so cuenta = 1+1
>> >>
>> >> Sebastian.
>> >
>> >
>
>



More information about the R-help mailing list