Tim Smith wrote:
> Hi,
>
> I have a 7000x7000 matrix, and each element is an integer. For each element,
> I want to apply the function :
>
> wt <- 0
> for(q in 1:count){
> wt <- wt + 0.5^(q-1)
> }
>
This is not a function! Maybe you want
helper <- function(count) sum(0.5^((1:count)-1))
tober 07, 2005 4:29 PM
> To: Tim Smith
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] Applying a function to each element of an array
>
> If there weren't an analytic solution to your problem,
> then you could build a vector of the answers from 1
> to the maximum in the
On Fri, 7 Oct 2005, Patrick Burns wrote:
> If there weren't an analytic solution to your problem,
> then you could build a vector of the answers from 1
> to the maximum in the matrix. Call that 'wtvec'. Then:
>
> ans <- array(NA, dim(A), dimnames(A))
> ans[] <- wtvec[as.vector(A)]
>
> should get
If there weren't an analytic solution to your problem,
then you could build a vector of the answers from 1
to the maximum in the matrix. Call that 'wtvec'. Then:
ans <- array(NA, dim(A), dimnames(A))
ans[] <- wtvec[as.vector(A)]
should get you what you want.
Patrick Burns
[EMAIL PROTECTED]
+4
TECTED]
> Sent: Friday, October 07, 2005 12:36 PM
> To: Berton Gunter
> Cc: 'Tim Smith'
> Subject: Re: [R] Applying a function to each element of an array
>
> On Fri, 7 Oct 2005, Berton Gunter wrote:
>
> > Well, since Sum(i=1 to i-n) =n*(n+1)/2, your loop simply gi
On Fri, 7 Oct 2005, Prof Brian Ripley wrote:
> If A is the matrix the answer is 2*(1 - 2^(-A)), which took about 10secs
> for an example of your size.
>
>> From \sum_{i=1}^n x^{1-i} = (1-x^{-n})/(1-x), E & OE.
NB: I have assumed n >= 1 here, as people nornally do when using 1:count.
> On Fri, 7
If A is the matrix the answer is 2*(1 - 2^(-A)), which took about 10secs
for an example of your size.
>From \sum_{i=1}^n x^{1-i} = (1-x^{-n})/(1-x), E & OE.
On Fri, 7 Oct 2005, Tim Smith wrote:
> I have a 7000x7000 matrix, and each element is an integer. For each
> element, I want to apply the
alyze the scientific learning
process." - George E. P. Box
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Tim Smith
> Sent: Friday, October 07, 2005 11:48 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Applying a function
To: r-help@stat.math.ethz.ch
Subject: [R] Applying a function to each element of an array
Hi,
I have a 7000x7000 matrix, and each element is an integer. For each element,
I want to apply the function :
wt <- 0
for(q in 1:count){
wt <- wt + 0.5^(q-1)
}
I get the value of 'count
Hi,
I have a 7000x7000 matrix, and each element is an integer. For each element, I
want to apply the function :
wt <- 0
for(q in 1:count){
wt <- wt + 0.5^(q-1)
}
I get the value of 'count' from the elements in the matrix , and want to store
the corresponding 'wt' value for that element.
10 matches
Mail list logo