Hi, I created list of 3 combination numbers (mycombos, around 3 lakh combinations) and counting the occurrence of those combination in another list. This comparision list (mylist) is having around 8000 records.I am using the following code. myCounts <- sapply(1:nrow(myCombos), FUN=function(i) { sum(sapply(myList, function(j) { sum(!is.na(match(c(myCombos[i,]), j)))})==3)}) The above code takes very long time to execute and is there any other effecting method which will reduce the time. -- Regards, Srivathsan.K [[alternative HTML version deleted]]
A reproducible example makes your problem easier to understand. ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey 2016-07-27 15:14 GMT+02:00 sri vathsan <srivibish at gmail.com>:> Hi, > > I created list of 3 combination numbers (mycombos, around 3 lakh > combinations) and counting the occurrence of those combination in another > list. This comparision list (mylist) is having around 8000 records.I am > using the following code. > > myCounts <- sapply(1:nrow(myCombos), FUN=function(i) { > sum(sapply(myList, function(j) { > sum(!is.na(match(c(myCombos[i,]), j)))})==3)}) > > The above code takes very long time to execute and is there any other > effecting method which will reduce the time. > -- > > Regards, > Srivathsan.K > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]
Not entirely sure I understand, but match() is already vectorized, so you should be able to lose the supply(). This would speed things up a lot. Please re-read ?match *carefully* . Bert On Jul 27, 2016 6:15 AM, "sri vathsan" <srivibish at gmail.com> wrote: Hi, I created list of 3 combination numbers (mycombos, around 3 lakh combinations) and counting the occurrence of those combination in another list. This comparision list (mylist) is having around 8000 records.I am using the following code. myCounts <- sapply(1:nrow(myCombos), FUN=function(i) { sum(sapply(myList, function(j) { sum(!is.na(match(c(myCombos[i,]), j)))})==3)}) The above code takes very long time to execute and is there any other effecting method which will reduce the time. -- Regards, Srivathsan.K [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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]]
Hi, Apologizes for the less information. Basically, myCombos is a matrix with 3 variables which is a triplet that is a combination of 79 codes. There are around 3lakh combination as such and it looks like below. V1 V2 V3 65 23 77 77 34 65 55 34 23 23 77 34 34 65 55 Each triplet will compare in a list (mylist) having 8177 elements which will looks like below. 77,65,34,23,55 65,23,77,65,55,34 77,34,65 55,78,56 98,23,77,65,34 Now I want to count the no of occurrence of the triplet in the above list. I.e., the triplet 65 23 77 is seen 3 times in the list. So my output looks like below V1 V2 V3 Freq 65 23 77 3 77 34 65 4 55 34 23 2 I hope, I made it clear this time. On Wed, Jul 27, 2016 at 7:00 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote:> Not entirely sure I understand, but match() is already vectorized, so you > should be able to lose the supply(). This would speed things up a lot. > Please re-read ?match *carefully* . > > Bert > > On Jul 27, 2016 6:15 AM, "sri vathsan" <srivibish at gmail.com> wrote: > > Hi, > > I created list of 3 combination numbers (mycombos, around 3 lakh > combinations) and counting the occurrence of those combination in another > list. This comparision list (mylist) is having around 8000 records.I am > using the following code. > > myCounts <- sapply(1:nrow(myCombos), FUN=function(i) { > sum(sapply(myList, function(j) { > sum(!is.na(match(c(myCombos[i,]), j)))})==3)}) > > The above code takes very long time to execute and is there any other > effecting method which will reduce the time. > -- > > Regards, > Srivathsan.K > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > > >-- Regards, Srivathsan.K Phone : 9600165206 [[alternative HTML version deleted]]