[R] faster way?

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Sep 11 08:47:21 CEST 2006



Rick Bischoff wrote:
> 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"]
> }



dsn2 <- dsn[order(-dsn$xhat),]
dsn2[,"cumx"] <- cumsum(dsn2[,"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.



More information about the R-help mailing list