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
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
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
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
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
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
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
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
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=
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
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
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
12 matches
Mail list logo