Re: [R] faster way?

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Mon 11 Sep 2006 - 07:01:40 GMT


Hi

not knowing dsn do you by chance looking for cumsum?

Or maybe something like this?

> x

 [1] 1 2 3 4 5 6 7 8 9 10
> y

 [1] 2 3 4 5 6 7 8 9 10 11
> x[1:9]+y[2:10]

[1] 4 6 8 10 12 14 16 18 20
>

HTH
Petr

On 10 Sep 2006 at 23:45, Rick Bischoff wrote:

To:             	R-Help <r-help@stat.math.ethz.ch>
From:           	Rick Bischoff <rdbisch@gmail.com>
Date sent:      	Sun, 10 Sep 2006 23:45:38 -0400
Subject:        	[R] faster way?

> Hi,
>
> Is there a faster way to do this? It takes forever, even on a
> moderately sized dataset.
>
>
> n <- dim(dsn)[1]
> dsn2 <- dsn[order(-dsn$xhat),]
> dsn2[1, "cumx"] <- dsn2[1, "xhat"]
>
> for (i in 2:n) {
> dsn2[i, "cumx"] <- dsn2[i - 1, "cumx"] + dsn2[i, "xhat"]
> }
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.

Petr Pikal
petr.pikal@precheza.cz



R-help@stat.math.ethz.ch 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. Received on Mon Sep 11 18:09:08 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 11 Sep 2006 - 08:30:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.