Skip to content

Multiple selection, renaming and saving the results

2 messages · Robin Corrià, David Winsemius

#
On Nov 25, 2011, at 12:50 PM, Robin Corri? wrote:

            
You should watch out since that is not a valid test for NA. If the  
values are NA rahter than "NA" you need to use !is.na()

You could set up a condition list which would really be a list of  
logical vectors and then loop through it like this:

consList[[1]] <- with(data1, treat=="I"&
                              block==1 &
                              sp=="acocar" &
                              d0!="NA")

(Then add more vectors to the list.)

for (cond in condList) { sel.spp[[i]] <- with(
                                             subset(data1,  
condList[[i]]),
                                                  spp(x=gx, y=gy,  
window=wA) )

                           acocar1I.dp[[i]] <-dval(sel.spp[[i]],  
25,2.5,18,20)
                           }

(You could then assemble the various calculations in a dataframe. All  
of this obviously untested.)

If you really are doing this for "all levels of sp, bloc, treat then  
there might be further option in the plyr pkg or with aggregate since  
they provide features for running through all existing combinations  
using the interaction function. The `expand.grid` function is  
sometimes useful for building data.frames as scaffolding to hold  
repeated calculations.