Re: [R] Avoiding loop

2011-04-18 Thread Filoche
Hi sire. This is exactly what I was looking for, thank you. With regards, Phil -- View this message in context: http://r.789695.n4.nabble.com/Avoiding-loop-tp3457963p3458152.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-pr

Re: [R] Avoiding loop

2011-04-18 Thread Dennis Murphy
Hi: Try the expm package. Using your example, > R = A%*%B > for(i in 1:100) + { +R = R%*%B + } > R [,1] [,2] [,3] [,4] [,5] [1,] 9.934879e+47 1.098761e+48 8.868476e+47 7.071831e+47 6.071370e+47 [2,] 1.492692e+48 1.650862e+48 1.332468e+48 1.0625

[R] Avoiding loop

2011-04-18 Thread Filoche
Hi everyone. I'm using matrix product such as : #Generate some data NCols = 5 NRows = 5 A = matrix(runif(NCols*NRows), ncol=NCols) B = matrix(runif(NCols*NRows), ncol=NCols) #First calculation R = A%*%B for(i in 1:100) { R = R%*%B } I would like to know if it was possible to avoi

Re: [R] avoiding loop

2009-11-03 Thread parkbomee
Thanks for your help. > Date: Mon, 2 Nov 2009 18:50:42 -0500 > Subject: Re: [R] avoiding loop > From: jholt...@gmail.com > To: bbom...@hotmail.com > CC: mtmor...@fhcrc.org; r-help@r-project.org > > The first thing I would suggest is convert your dataframes to matrices

Re: [R] avoiding loop

2009-11-02 Thread jim holtman
9.86 1.7 9.86 1.7 > "list" 9.64 1.7 9.64 1.7 > "exp"7.12 1.2 7.12 1.2 > "as.data.frame.integer" 5.98 1.0 8.10 1.4 > >> To

Re: [R] avoiding loop

2009-11-02 Thread parkbomee
st" 9.64 1.7 9.64 1.7 "exp" 7.12 1.2 7.12 1.2 "as.data.frame.integer" 5.98 1.0 8.10 1.4 > To: bbom...@hotmail.com > CC: jholt...@gmail.com; r-help@r-project.org > Subject

Re: [R] avoiding loop

2009-11-01 Thread Martin Morgan
that the result of tapply2 is always a vector of the same length even when some time intervals never have choice==1. Because tapply in these examples seems so fast compared to your calculation, I wonder whether optim is evaluating your function many times, and that reformulating the optimization might l

Re: [R] avoiding loop

2009-11-01 Thread parkbomee
14.1 "FUN" 94.16 16.5 94.16 16.5 . . . . . > Date: Sun, 1 Nov 2009 15:35:41 -0400 > Subject: Re: [R] avoiding loop > From: jholt...@gmail.com > To: bbom...@hotmail.com > CC: dwinsem...@comcast.net; d.rizopou...@erasmusmc.nl; r-help@r-pr

Re: [R] avoiding loop

2009-11-01 Thread jim holtman
eem to improve my code > much. > I am using this inside of an optimization function, > and it still takes more than it needs... > > > >> CC: bbom...@hotmail.com; r-help@r-project.org >> From: dwinsem...@comcast.net >> To: d.rizopou...@erasmusmc.nl >> Subject

Re: [R] avoiding loop

2009-11-01 Thread Charles C. Berry
project.org/web/packages/inline/index.html HTH, Chuck CC: bbom...@hotmail.com; r-help@r-project.org From: dwinsem...@comcast.net To: d.rizopou...@erasmusmc.nl Subject: Re: [R] avoiding loop Date: Sat, 31 Oct 2009 22:26:17 -0400 This is pretty much equivalent: tapply(DF$value[DF$choice=

Re: [R] avoiding loop

2009-10-31 Thread parkbomee
d.rizopou...@erasmusmc.nl > Subject: Re: [R] avoiding loop > Date: Sat, 31 Oct 2009 22:26:17 -0400 > > This is pretty much equivalent: > > tapply(DF$value[DF$choice==1], DF$time[DF$choice==1], sum) / > tapply(DF$value, DF$time, sum) > > And both will probably fail if th

Re: [R] avoiding loop

2009-10-31 Thread David Winsemius
This is pretty much equivalent: tapply(DF$value[DF$choice==1], DF$time[DF$choice==1], sum) / tapply(DF$value, DF$time, sum) And both will probably fail if the number of groups with choice==1 is different than the number overall. -- David. On Oct 31, 2009, at 5:14 PM, Dimitris Rizopo

Re: [R] avoiding loop

2009-10-31 Thread Dimitris Rizopoulos
one approach is the following: # say 'DF' is your data frame, then with(DF, { ind <- choice == 1 n <- tapply(value[ind], time[ind], sum) d <- tapply(value, time, sum) n / d }) I hope it helps. Best, Dimitris parkbomee wrote: Hi all, I am trying to figure out a way to improv

[R] avoiding loop

2009-10-31 Thread parkbomee
Hi all, I am trying to figure out a way to improve my code's efficiency by avoiding the use of loop. I want to calculate a conditional mean(?) given time. For example, from the data below, I want to calculate sum((value|choice==1)/sum(value)) across time. Is there a way to do it without using a