Hi guys,

I am trying to replace all elements of earth that are equal to zero with their 
corresponding elements in mars. I can do the replace with a bunch of for-loops, 
but I don't think this is the R way of doing things.

my_list <- list( earth=array(c(0,0,45,0,0,45,0,45),dim=c(2,2,2)), 
mars=array(c(8:1),dim=c(2,2,2)))
my_list
for (i in c(1:2)) {
                for (j in c(1:2)) {
                                for (k in c(1:2)) {
                                                if (my_list$earth[i,j,k] == 0) {
                                                                
my_list$earth[i,j,k] <- my_list$mars[i,j,k]
                                                }
                                }
                }
}
my_list

Do you guys have any suggestions for getting rid of the ugly for-loops?

Many thanks,

Fernando Álvarez

Nordea e-Markets
Strandgade 3
PO Box 850
DK-0900 Copenhagen C
Denmark
Tel.: +45 33 33 32 67
Mobile: +45 61 55 27 54

This transmission is intended solely for the person or entity to whom it is 
addressed. It may contain privileged and confidential information. If you are 
not the intended recipient, please be notified that any dissemination, 
distribution or copying is strictly prohibited. If you have received this 
transmission by mistake, please let us know and then delete it from your system.

P Please consider the impact on the environment before printing this e-mail.


        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to