[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

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

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. __

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 so that you are not having

Re: [R] avoiding loop

2009-11-02 Thread parkbomee
...@gmail.com; r-help@r-project.org Subject: Re: [R] avoiding loop From: mtmor...@fhcrc.org Date: Sun, 1 Nov 2009 22:14:09 -0800 parkbomee bbom...@hotmail.com writes: Thank you all. What Chuck has suggested might not be applicable since the number of different times is around 40,000

Re: [R] avoiding loop

2009-11-02 Thread jim holtman
1.7 list 9.64 1.7 9.64 1.7 exp7.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 From

Re: [R] avoiding loop

2009-11-01 Thread Charles C. Berry
/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==1], DF$time[DF$choice==1], sum

Re: [R] avoiding loop

2009-11-01 Thread jim holtman
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 Date: Sat, 31 Oct 2009 22:26:17 -0400

Re: [R] avoiding loop

2009-11-01 Thread parkbomee
...@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==1], DF$time[DF$choice==1], sum) / tapply(DF$value, DF$time

Re: [R] avoiding loop

2009-11-01 Thread Martin Morgan
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-project.org What you need to do is to understand how to use Rprof so that you can determine where the time is being spent

[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

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 improve

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

Re: [R] avoiding loop

2009-10-31 Thread parkbomee
...@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 the number of groups with choice==1