|
Re: masking z values (extract or subset on a 3-d array): msg#00062lang.r.geo
On Fri, 26 May 2006, Andy Bunn wrote: > This is driving me nuts. I have a 3-D array that holds x,y,z coordinates > from multiple experiments. I need to clean the data before making it sp > objects. I want to set all z-values < 0 to 0. In a 2-D matrix this is > trivial e.g., x[,x[1,]<0] <- 0. But I'm stumped on how to do this on a 3-D > array without a loop. Given an array: > > 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? a <- array(rnorm(64), c(4,4,4)) inds <- which(a < 0, arr.ind=TRUE) a[inds] <- 0 should do it. Roger > > > Thanks, Andy > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@xxxxxxxxxxxxxxxxx > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand@xxxxxx
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: problems loading spproj library for transform(), Morten Sickel |
|---|---|
| Next by Date: | Re: problems loading spproj library for transform(), Roger Bivand |
| Previous by Thread: | masking z values (extract or subset on a 3-d array), Andy Bunn |
| Next by Thread: | Re: masking z values (extract or subset on a 3-d array), Andy Bunn |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |