[R] aggregate with cumsum

Gabor Grothendieck ggrothendieck at gmail.com
Mon Oct 18 16:02:38 CEST 2010


On Mon, Oct 18, 2010 at 9:55 AM, Bond, Stephen <Stephen.Bond at cibc.com> wrote:
> Gabor,
>
> You are suggesting some very advanced usage that I do not understand, but it seems this is not what I meant when I said loop.
> I have a df with 47k rows and each of these is fed to a 'predict' which will output about 62 rows, so the number of groups is very large and I implied that I would go through the 47k x 62 rows with
>
> For (jj in (set of 47k values)) # tmp.df=big.df[big.df$group==jj,] to subset
>                                # and then sum
>
> Which is very slow. I discovered that even creating the dataset is super slow as I use write.table
>
> The clogging comes from
>
> write.table(tmp,"predcom.csv",row.names=FALSE,col.names=FALSE,append=TRUE,sep=',')
>
> Can anybody suggest a faster way of appending to a text file??
>
> All comments are appreciated.

If the problem is to sum each row of a matrix then rowSums can do that
without a loop.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list