Dear R community
I have stored the results of arrays in a list consist of J-components (say 200
components). Each component containing same no of columns but may be different
no of rows. e.g
[[1]]
[,1] [,2] [,3] [,4] [,5]
[1,] 4 0 0 0 0
[2,] 4 3 4 0 0
[3,] 4 3 4 0 0
[4,] 4 3 0 0 0
[[2]]
[,1] [,2] [,3] [,4] [,5]
[1,] 4 0 0 0 0
[2,] 4 4 3 0 0
[3,] 4 4 3 0 0
[4,] 4 4 0 0 0
[5,] 4 4 0 0 0
[[3]]
[,1] [,2] [,3] [,4] [,5]
[1,] 4 0 0 0 0
[2,] 4 4 1 0 0
[3,] 4 4 1 0 0
[4,] 4 4 0 0 0
For 200 components i want to make a frequency table. How can i make a frequency
table of these components or the most repeated component out of all? Any help in
this regard will be appreciated.
Muhammad Azam
[[alternative HTML version deleted]]
If want you want is the summary from all of them, then 'rbind' the data together into one matrix and analyze it: totalMat <- do.call(rbind, listOfMatrices) On Wed, Sep 10, 2008 at 11:49 AM, Muhammad Azam <mazam72 at yahoo.com> wrote:> Dear R community > I have stored the results of arrays in a list consist of J-components (say 200 components). Each component containing same no of columns but may be different no of rows. e.g > [[1]] > [,1] [,2] [,3] [,4] [,5] > [1,] 4 0 0 0 0 > [2,] 4 3 4 0 0 > [3,] 4 3 4 0 0 > [4,] 4 3 0 0 0 > > [[2]] > [,1] [,2] [,3] [,4] [,5] > [1,] 4 0 0 0 0 > [2,] 4 4 3 0 0 > [3,] 4 4 3 0 0 > [4,] 4 4 0 0 0 > [5,] 4 4 0 0 0 > > [[3]] > [,1] [,2] [,3] [,4] [,5] > [1,] 4 0 0 0 0 > [2,] 4 4 1 0 0 > [3,] 4 4 1 0 0 > [4,] 4 4 0 0 0 > > For 200 components i want to make a frequency table. How can i make a frequency table of these components or the most repeated component out of all? Any help in this regard will be appreciated. > > > Muhammad Azam > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
You might try apply(t(sapply(l,apply,2,sum)),2,sum) --Adam On Wed, 10 Sep 2008, Muhammad Azam wrote:> Dear R community> I have stored the results of arrays in a list consist of J-components (say > 200 components). Each component containing same no of columns but may be > different no of rows. e.g> [[1]] > [,1] [,2] [,3] [,4] [,5] > [1,] 4 0 0 0 0 > [2,] 4 3 4 0 0 > [3,] 4 3 4 0 0 > [4,] 4 3 0 0 0 > > [[2]] > [,1] [,2] [,3] [,4] [,5] > [1,] 4 0 0 0 0 > [2,] 4 4 3 0 0 > [3,] 4 4 3 0 0 > [4,] 4 4 0 0 0 > [5,] 4 4 0 0 0 > > [[3]] > [,1] [,2] [,3] [,4] [,5] > [1,] 4 0 0 0 0 > [2,] 4 4 1 0 0 > [3,] 4 4 1 0 0 > [4,] 4 4 0 0 0 > > For 200 components i want to make a frequency table. How can i make a > frequency table of these components or the most repeated component out of > all? Any help in this regard will be appreciated. > > > Muhammad Azam > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >
May be i could not explain properly. Actually there are components of
list i.e. [[1]] to [[500]]. Each component containing r-rows (may be
different for each [[ k ]] and c-columns same for all). I have to
compare all the [[ k ]] components of that list and found the one
appearing maximum no of times. e.g. from three components [[1]] to
[[3]] given below. The most repeated is
[,1] [,2] [,3] [,4] [,5]
[1,] 4 0 0 0 0
[2,] 4 3 4 0 0
[3,] 4 3 4 0 0
[4,] 4 3 0 0 0Please help to find it. Thanks and
best regards
Muhammad Azam
----- Original Message ----
From: jim holtman <jholtman@gmail.com>
To: Muhammad Azam <mazam72@yahoo.com>
Cc: R-help request <r-help-request@r-project.org>; R Help
<r-help@r-project.org>
Sent: Wednesday, September 10, 2008 5:59:28 PM
Subject: Re: [R] request: most repeated component of a list
If want you want is the summary from all of them, then 'rbind' the
data together into one matrix and analyze it:
totalMat <- do.call(rbind, listOfMatrices)
On Wed, Sep 10, 2008 at 11:49 AM, Muhammad Azam <mazam72@yahoo.com>
wrote:> Dear R community
>
I have stored the results of arrays in a list consist of J-components
(say 200 components). Each component containing same no of columns but
may be different no of rows. e.g> [[1]]
> [,1] [,2] [,3] [,4] [,5]
> [1,] 4 0 0 0 0
> [2,] 4 3 4 0 0
> [3,] 4 3 4 0 0
> [4,] 4 3 0 0 0
>
> [[2]]
> [,1] [,2] [,3] [,4] [,5]
> [1,] 4 0 0 0 0
> [2,] 4 3 4 0 0
> [3,] 4 3 4 0 0
> [4,] 4 3 0 0 0
>
> [[3]]
> [,1] [,2] [,3] [,4] [,5]
> [1,] 4 0 0 0 0
> [2,] 4 4 1 0 0
> [3,] 4 4 1 0 0
> [4,] 4 4 0 0 0
> [5,] 4 4 0 0 0
>
>
For 200 components i want to make a frequency table. How can i make a
frequency table of these components or the most repeated component out
of all? Any help in this regard will be appreciated.>
>
> Muhammad Azam
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
[[alternative HTML version deleted]]
Thanks for the effort but still we are far from the desired result. May be this
example will help you to understand the situation. Example
a1=c(1:12); a1=array(a1,dim=c(3,4)); a2=c(1:12); a2=array(a2,dim=c(3,4));
a3=c(1:16)
a3=array(a3,dim=c(4,4));
a=list(a1,a2,a3);
a
[[1]]
[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12
[[2]]
[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12
[[3]]
[,1] [,2] [,3] [,4]
[1,] 1 5 9 13
[2,] 2 6 10 14
[3,] 3 7 11 15
[4,] 4 8 12 16
Here [[1]] and [[2]] are same out of three (internal values wise). The whole
array [[1]] or [[2]] is in majority. So i want to get the whole array or
component of list which is in majority. The result should be like this
[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12
Hope it is much more clear as before.
best regards
Muhammad Azam
----- Original Message ----
From: Adam D. I. Kramer <adik-rhelp@ilovebacon.org>
To: Muhammad Azam <mazam72@yahoo.com>
Cc: R Help <r-help@r-project.org>
Sent: Thursday, September 11, 2008 9:53:40 AM
Subject: Re: [R] request: most repeated component of a list
That is indeed different from what I thought the first time.
x <- sapply(1:length(l), function(x) {
sum(sapply(l, function(y) {
if ( nrow(l[[x]]) != nrow(y) | ncol(l[[x]]) != ncol(y) ) FALSE
else sum(y != l[[x]]) == 0
}))
} )
names(x) <- names(l)
Then, x has the same names as l, and x[i] is the number of matches that
l[[i]] has...so you want the index or indices of max(x).
--Adam
On Thu, 11 Sep 2008, Muhammad Azam wrote:
> May be i could not explain properly. Actually there are components of
> list i.e. [[1]] to [[500]]. Each component containing r-rows (may be
> different for each [[ k ]] and c-columns same for all). I have to
> compare all the [[ k ]] components of that list and found the one
> appearing maximum no of times. e.g. from three components [[1]] to
> [[3]] given below. The most repeated is
>
> [,1] [,2] [,3] [,4] [,5]
> [1,] 4 0 0 0 0
> [2,] 4 3 4 0 0
> [3,] 4 3 4 0 0
> [4,] 4 3 0 0 0Please help to find it. Thanks and
>
> best regards
> Muhammad Azam
>
>
> ----- Original Message ----
> From: jim holtman <jholtman@gmail.com>
> To: Muhammad Azam <mazam72@yahoo.com>
> Cc: R-help request <r-help-request@r-project.org>; R Help
<r-help@r-project.org>
> Sent: Wednesday, September 10, 2008 5:59:28 PM
> Subject: Re: [R] request: most repeated component of a list
>
> If want you want is the summary from all of them, then 'rbind' the
> data together into one matrix and analyze it:
>
> totalMat <- do.call(rbind, listOfMatrices)
>
> On Wed, Sep 10, 2008 at 11:49 AM, Muhammad Azam <mazam72@yahoo.com>
wrote:
>> Dear R community
>>
> I have stored the results of arrays in a list consist of J-components
> (say 200 components). Each component containing same no of columns but
> may be different no of rows. e.g
>> [[1]]
>> [,1] [,2] [,3] [,4] [,5]
>> [1,] 4 0 0 0 0
>> [2,] 4 3 4 0 0
>> [3,] 4 3 4 0 0
>> [4,] 4 3 0 0 0
>>
>> [[2]]
>> [,1] [,2] [,3] [,4] [,5]
>> [1,] 4 0 0 0 0
>> [2,] 4 3 4 0 0
>> [3,] 4 3 4 0 0
>> [4,] 4 3 0 0 0
>>
>> [[3]]
>> [,1] [,2] [,3] [,4] [,5]
>> [1,] 4 0 0 0 0
>> [2,] 4 4 1 0 0
>> [3,] 4 4 1 0 0
>> [4,] 4 4 0 0 0
>> [5,] 4 4 0 0 0
>>
>>
> For 200 components i want to make a frequency table. How can i make a
> frequency table of these components or the most repeated component out
> of all? Any help in this regard will be appreciated.
>>
>>
>> Muhammad Azam
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
[[alternative HTML version deleted]]
Thanks a lot for this effort.
----- Original Message ----
From: Dimitris Rizopoulos <d.rizopoulos@erasmusmc.nl>
To: Muhammad Azam <mazam72@yahoo.com>
Cc: adik@ilovebacon.org; R Help <r-help@r-project.org>
Sent: Thursday, September 11, 2008 10:52:16 AM
Subject: Re: [R] request: most repeated component of a list
try the following:
ff <- function (x) {
do.call("paste", c(as.data.frame(x), sep = "\r", collapse
= ""))
}
pats <- sapply(a, ff)
ind <- which.max(table(pats))
a[[ind]]
I hope it helps.
Best,
Dimitris
> Thanks for the effort but still we are far from the desired result. May be
> this example will help you to understand the situation. Example
> a1=c(1:12); a1=array(a1,dim=c(3,4)); a2=c(1:12);
> a2=array(a2,dim=c(3,4)); a3=c(1:16)
> a3=array(a3,dim=c(4,4));
> a=list(a1,a2,a3);
> a
> [[1]]
> [,1] [,2] [,3] [,4]
> [1,] 1 4 7 10
> [2,] 2 5 8 11
> [3,] 3 6 9 12
>
> [[2]]
> [,1] [,2] [,3] [,4]
> [1,] 1 4 7 10
> [2,] 2 5 8 11
> [3,] 3 6 9 12
>
> [[3]]
> [,1] [,2] [,3] [,4]
> [1,] 1 5 9 13
> [2,] 2 6 10 14
> [3,] 3 7 11 15
> [4,] 4 8 12 16
>
> Here [[1]] and [[2]] are same out of three (internal values wise). The
> whole array [[1]] or [[2]] is in majority. So i want to get the whole
> array or component of list which is in majority. The result should be like
> this
> [,1] [,2] [,3] [,4]
> [1,] 1 4 7 10
> [2,] 2 5 8 11
> [3,] 3 6 9 12
>
> Hope it is much more clear as before.
>
> best regards
> Muhammad Azam
>
>
> ----- Original Message ----
> From: Adam D. I. Kramer <adik-rhelp@ilovebacon.org>
> To: Muhammad Azam <mazam72@yahoo.com>
> Cc: R Help <r-help@r-project.org>
> Sent: Thursday, September 11, 2008 9:53:40 AM
> Subject: Re: [R] request: most repeated component of a list
>
> That is indeed different from what I thought the first time.
>
> x <- sapply(1:length(l), function(x) {
> sum(sapply(l, function(y) {
> if ( nrow(l[[x]]) != nrow(y) | ncol(l[[x]]) != ncol(y) ) FALSE
> else sum(y != l[[x]]) == 0
> }))
> } )
>
> names(x) <- names(l)
>
> Then, x has the same names as l, and x[i] is the number of matches that
> l[[i]] has...so you want the index or indices of max(x).
>
> --Adam
>
> On Thu, 11 Sep 2008, Muhammad Azam wrote:
>
>> May be i could not explain properly. Actually there are components of
>> list i.e. [[1]] to [[500]]. Each component containing r-rows (may be
>> different for each [[ k ]] and c-columns same for all). I have to
>> compare all the [[ k ]] components of that list and found the one
>> appearing maximum no of times. e.g. from three components [[1]] to
>> [[3]] given below. The most repeated is
>>
>> [,1] [,2] [,3] [,4] [,5]
>> [1,] 4 0 0 0 0
>> [2,] 4 3 4 0 0
>> [3,] 4 3 4 0 0
>> [4,] 4 3 0 0 0Please help to find it. Thanks and
>>
>> best regards
>> Muhammad Azam
>>
>>
>> ----- Original Message ----
>> From: jim holtman <jholtman@gmail.com>
>> To: Muhammad Azam <mazam72@yahoo.com>
>> Cc: R-help request <r-help-request@r-project.org>; R Help
>> <r-help@r-project.org>
>> Sent: Wednesday, September 10, 2008 5:59:28 PM
>> Subject: Re: [R] request: most repeated component of a list
>>
>> If want you want is the summary from all of them, then 'rbind'
the
>> data together into one matrix and analyze it:
>>
>> totalMat <- do.call(rbind, listOfMatrices)
>>
>> On Wed, Sep 10, 2008 at 11:49 AM, Muhammad Azam
<mazam72@yahoo.com>
>> wrote:
>>> Dear R community
>>>
>> I have stored the results of arrays in a list consist of J-components
>> (say 200 components). Each component containing same no of columns but
>> may be different no of rows. e.g
>>> [[1]]
>>> [,1] [,2] [,3] [,4] [,5]
>>> [1,] 4 0 0 0 0
>>> [2,] 4 3 4 0 0
>>> [3,] 4 3 4 0 0
>>> [4,] 4 3 0 0 0
>>>
>>> [[2]]
>>> [,1] [,2] [,3] [,4] [,5]
>>> [1,] 4 0 0 0 0
>>> [2,] 4 3 4 0 0
>>> [3,] 4 3 4 0 0
>>> [4,] 4 3 0 0 0
>>>
>>> [[3]]
>>> [,1] [,2] [,3] [,4] [,5]
>>> [1,] 4 0 0 0 0
>>> [2,] 4 4 1 0 0
>>> [3,] 4 4 1 0 0
>>> [4,] 4 4 0 0 0
>>> [5,] 4 4 0 0 0
>>>
>>>
>> For 200 components i want to make a frequency table. How can i make a
>> frequency table of these components or the most repeated component out
>> of all? Any help in this regard will be appreciated.
>>>
>>>
>>> Muhammad Azam
>>>
>>>
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>>
>>
>> --
>> Jim Holtman
>> Cincinnati, OH
>> +1 513 646 9390
>>
>> What is the problem that you are trying to solve?
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
[[alternative HTML version deleted]]
Muhammad Azam wrote:> Thanks for the effort but still we are far from the desired result. May be this example will help you to understand the situation. Example > a1=c(1:12); a1=array(a1,dim=c(3,4)); a2=c(1:12); a2=array(a2,dim=c(3,4)); a3=c(1:16) > a3=array(a3,dim=c(4,4)); > a=list(a1,a2,a3); > a > [[1]] > [,1] [,2] [,3] [,4] > [1,] 1 4 7 10 > [2,] 2 5 8 11 > [3,] 3 6 9 12 > > [[2]] > [,1] [,2] [,3] [,4] > [1,] 1 4 7 10 > [2,] 2 5 8 11 > [3,] 3 6 9 12 > > [[3]] > [,1] [,2] [,3] [,4] > [1,] 1 5 9 13 > [2,] 2 6 10 14 > [3,] 3 7 11 15 > [4,] 4 8 12 16 > > Here [[1]] and [[2]] are same out of three (internal values wise). The whole array [[1]] or [[2]] is in majority. So i want to get the whole array or component of list which is in majority. The result should be like this > [,1] [,2] [,3] [,4] > [1,] 1 4 7 10 > [2,] 2 5 8 11 > [3,] 3 6 9 12 >Hi Muhammad, If I have understood the problem, you want to select one or more components of a list containing matrices, arrays or data frames that are least dissimilar to one or more other components of that list. Dissimilarity is defined by the sum of mismatching elements. Because you can have more than one set of pairs that are "least dissimilar", the attached function returns the indices of the "least dissimilar" pairs and the "least dissimilar" components. Hope it does what you want. Jim -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: find.most.repeated.R URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080912/d7afb477/attachment.pl>