Succinct is good, but reproducible is even more important. Think ?dput or ?sample so we have some data like you do, your current algorithm, or at least a desired output example (again using dput) --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnew...@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity.
Walter Anderson <wandrso...@gmail.com> wrote: >On 03/16/2012 12:23 PM, Sarah Goslee wrote: >> There's almost certainly a better way, but I'd be more inclined to >look for >> it if you'd provide a small reproducible example so I could actually >try it. >> Without knowing the structure of your data, it's very hard to offer >> alternatives. >> >> Sarah >> >> On Fri, Mar 16, 2012 at 12:59 PM, Walter >Anderson<wandrso...@gmail.com> wrote: >>> I am working on a simulation where I need to count the number of >matches for >>> an arbitrary pattern in a large sequence of binomial factors. My >current >>> code is >>> >>> for(indx in 1:(length(bin.05)-3)) >>> if ((bin.05[indx] == test.pattern[1])&& (bin.05[indx+1] == >>> test.pattern[2])&& (bin.05[indx+2] == test.pattern[3])) >>> return.values$count.match.pattern[1] = >>> return.values$count.match.pattern[1] + 1 >>> >>> Since I am running the above code for each simulation multiple times >on >>> sequences of 10,000,000 factors the code is taking longer than I >would like. >>> Is there a better (more "R" way of achieving the same answer? >>> >>> Walter Anderson >>> >Thank you for responding. I was attempting to keep my code snippet >small, since my last question which contained what I thought was a >small >(but complete example) only received responses that the >provided code was not succinct enough. > >the provided sequence of factors (bin.05) consist of a vector of up of >factors like this; [T,T,O,T,O,O,T,T,T,...] in a variety of different >proportions. The search pattern consists of any one of the >combinations >of the factors (T & O) in a set of three, ie. [T,T,O] > >______________________________________________ >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. ______________________________________________ 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.