Skip to content
Prev 1045 / 29559 Next

masking z values (extract or subset on a 3-d array)

Thanks, but I'm looking to set only the values from one dimension to zero.
As above, I just want to set the 'z' values to 0 if they are less than one.
This works:

  foo <- array(rnorm(24), dim=c(4,3,2))
  dimnames(foo) <-list(NULL,c('x','y','z'),c('Experiment1','Experiment2'))
  foo[,'z',]
  #How can I set foo[,'z',]<0 to 0
  for(i in 1:2){
    foo[foo[,'z',i]<0,'z',i] = 0
  }
  foo

But it seems like one should be able to do this with apply or just '['. I'm
at a loss.

-A