Re: [R] Array arithmetic

From: Benilton Carvalho <bcarvalh_at_jhsph.edu>
Date: Thu, 06 Mar 2008 14:07:26 -0500

no, it won't.

you're doing the right math on the "valid" subset... but you're not returning the zeros where needed.... therefore, the whole thing will get recycled to match the dimensions.

b

On Mar 6, 2008, at 2:03 PM, Henrique Dallazuanna wrote:

> I think this should work:
>
> array(A[abs(B) > 10e-5]/B[abs(B) > 10e-5], dim=c(L, M, N, P))
>
> On 06/03/2008, Gang Chen <gangchen6_at_gmail.com> wrote:
>> I have two arrays A and B with dimensions of (L, M, N, P) and (L, M,
>> N), and I want to do
>>
>> for (i in 1:L) {
>> for (j in 1:M) {
>> for (k in 1:N) {
>> if (abs(B[i, j, k]) > 10e-5) C[i, j, k,] <- A[i, j, k,]/B[i, j, k]
>> else C[i, j, k,] <- 0
>> }
>> }
>> }
>>
>> How can I get C more efficiently than looping?
>>
>> Thanks,
>> Gang
>>
>> ______________________________________________
>> R-help_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 06 Mar 2008 - 19:26:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 06 Mar 2008 - 19:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive