[R] apply and cousins

William Dunlap wdunlap at tibco.com
Wed Jun 8 18:50:37 CEST 2016


>It is easy in a loop but that will take ages. Is there any vectorised
>apply-like solution to this?

If you showed the loop that takes ages, along with small inputs for
it (and an indication of how to expand those small inputs to big ones),
someone might be able to show you some code that does the
same thing in less time.


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Jun 8, 2016 at 9:41 AM, John Logsdon <j.logsdon at quantex-research.com
> wrote:

> Folks
>
> Is there any way to get the row index into apply as a variable?
>
> I want a function to do some sums on a small subset of some very long
> vectors, rolling through the whole vectors.
>
> apply(X,1,function {do something}, other arguments)
>
> seems to be the way to do it.
>
> The subset I want is the most recent set of measurements only - perhaps a
> couple of hundred out of millions - but I can't see how to index each
> value.  The ultimate output should be a matrix of results the length of
> the input vector.  But to do the sum I need to access the current row
> number.
>
> It is easy in a loop but that will take ages. Is there any vectorised
> apply-like solution to this?
>
> Or does apply etc only operate on each row at a time, independently of
> other rows?
>
>
> Best wishes
>
> John
>
> John Logsdon
> Quantex Research Ltd
> +44 161 445 4951/+44 7717758675
>
> ______________________________________________
> 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]]



More information about the R-help mailing list