# [R] Information Frequency problem calculation

arun smartpink111 at yahoo.com
Tue Oct 8 17:05:59 CEST 2013

```Dear Jarod,

You can call me Arun.
mauro    francesco    E234
luca    giuseppe    E5578
luca    franco    E5569
maria    luca    E4556
maria    mauro    E4556
luisa    mara    E4755
mara    luca    E234
luigi    veronica    E234

res <- do.call(rbind,lapply(unique(c(a[,1],a[,2])),function(x) {data.frame(RESULTS= x,GROUP1= sum(a[,1] %in% x), GROUP2=sum(a[,2] %in% x),stringsAsFactors=FALSE)}))
res
#     RESULTS GROUP1 GROUP2
#1      mauro      2      1
#2       luca      2      2
#3      maria      2      0
#4      luisa      1      0
#5       mara      1      1
#6      luigi      1      0
#7  francesco      0      1
#8   giuseppe      0      1
#9     franco      0      1
#10  veronica      0      2

A.K.

----- Original Message -----
From: "jarod_v6 at libero.it" <jarod_v6 at libero.it>
To: smartpink111 at yahoo.com
Cc:
Sent: Tuesday, October 8, 2013 10:07 AM
Subject: Re: [R] Information Frequency problem calculation

Dear Master,

I have this long database of breeder divide in two list. eache list have
particular group rna identify (catcghory of birds)

GROUP1    GROUP2
NAME1    NAME2    RNA
mauro    francesco    E234
luca    giuseppe    E5578
luca    franco    E5569
maria    luca    E4556
maria    mauro    E4556"
luisa    mara    E4755
mara    luca    E234
luigi    veronica    E234
mauro    veronica    E235

What I want is to have a frequency of presence of all my data:
So :

RESULTS    group1    group2
MAURO     2    1

I want know how many times one name it is found in group 1 or in group2 and
how many times have different RNA (identify of group).
Thanks for help!!
Jarod

>----Messaggio originale----
>Da: smartpink111 at yahoo.com
>Data: 08/10/2013 15.12
>A: "jarod_v6 at libero.it"<jarod_v6 at libero.it>
>Ogg: Re: R: Re: [R] Information Frequency problem calculation
>
>Hi Jarod,
>
>Could you show your expected outcome as this is still confusing.  As I
understand from your initial post, you are comparing two columns from your data
frame (ie. Name1 and Name2).  My idea was to compare each entry of the first
column and compare it with the full set of second column to see where they are
the same.
>for example.
>mauro francesco E234
>luca  giuseppe  E5578
>luca  franco  E5569
>maria luca E4556
>
> lapply(seq_len(nrow(a)),function(i) a[i,1])
>[[1]]
>[1] "mauro"
>
>[[2]]
>[1] "luca"
>
>[[3]]
>[1] "luca"
>
>[[4]]
>[1] "maria"
>
>[[5]]
>[1] "maria"
>
>
>lapply(seq_len(nrow(a)),function(i) sum(a[,2]%in% a[i,1])) #here, it
calculates the sum of the number of matches for each entry of column 1.
>[[1]]
>[1] 1
>
>[[2]]
>[1] 1
>
>[[3]]
>[1] 1
>
>[[4]]
>[1] 0
>
>[[5]]
>[1] 0
>
>
>
> I think this is not you wanted.  Your idea of  "ex mauro it is
>presence on E234 and E4556 so I found 2 time 5 condition  and 1 time fo
single
>condition" is a bit confusing.
>
>Did you meant that "E4556" is repeated twice, so it should be 2 times?.  As I
pointed out, if the expected result table is also shown, it would be easier to
understand than words.
>
>
>A.K.
>
>
>
>
>
>
>----- Original Message -----
>From: "jarod_v6 at libero.it" <jarod_v6 at libero.it>
>To: smartpink111 at yahoo.com
>Cc:
>Sent: Tuesday, October 8, 2013 3:57 AM
>Subject: R: Re: [R] Information Frequency problem calculation
>
>Thanks so much for your suggestion.. I have a little difficult to understand
>the comand .. could you help me?
>So I interested in calculate the frequence of some names  ex mauro it is
>presence on E234 and E4556 so I found 2 time 5 condition  and 1 time fo
single
>condition
>
>>----Messaggio originale----
>>Da: smartpink111 at yahoo.com
>>Data: 07/10/2013 18.45
>>A: "jarod_v6 at libero.it"<jarod_v6 at libero.it>
>>Cc: "R help"<r-help at r-project.org>
>>Ogg: Re: [R] Information Frequency problem calculation
>>
>>Hi,
>>Not sure what your expected output would be:
>>mauro francesco E234
>>luca  giuseppe  E5578
>>luca  franco  E5569
>>maria luca E4556"
>maria   mauro E4556
>
>
>
>>sapply(seq_len(nrow(a)),function(i) sum(a[,2] %in% a[i,1]))
>>#[1] 0 1 1 0
>>
>>
>>A.K.
>>
>>
>>
>>
>>
>>----- Original Message -----
>>From: "jarod_v6 at libero.it" <jarod_v6 at libero.it>
>>To: r-help at r-project.org
>>Cc:
>>Sent: Monday, October 7, 2013 12:09 PM
>>Subject: [R] Information Frequency problem calculation
>>
>>Dear All,
>>
>>I Have a dataframe like that:
>>
>>Name1 Name2 category
>>
>>mauro francesco E234
>>luca   giuseppe  E5578
>>luca   franco  E5569
>>maria luca E4556
>>...
>>I would like to calculate the frequency of many time in my data I found  in
>>the list name:
>>
>>name1<-as.character(a[,1])
>>name2<-as.character(a[,2])
>>category<-as.character(a[,3])
>>
>>for(i in 1:lenght(name1)){
>>re <-which(name1 == name2)
>>
>>}
>>
>>So how can create a table of frequncy of many times I found a name in
column
>>one respect to the second ?
>>M.
>>
>>______________________________________________
>>R-help at r-project.org mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help