faster way?
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 at stat.math.ethz.ch> From: Rick Bischoff <rdbisch at 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 at 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 at precheza.cz