On Mon, Aug 08, 2005 at 04:07:10PM +0100, Prof Brian Ripley wrote:
> On Mon, 8 Aug 2005, Tamas K Papp wrote:
>
> > m <- function(b) {sapply(b, function(bb) {
> > if (bb < 0) {bb} else {if (bb>d) {bb-d} else 0}
> > })}
>
> Why use sapply?
>
> r[] <- ifelse(r >= d, r-d, ifelse(r >= 0, 0, r))
>
> is one more efficient way.
Thank you very much, this speeded up things considerably. I need this
operation to ignore the first column of the matrix, is there a more
efficient way than
r[,-1] <- ifelse(r[,-1] >= d, r[,-1]-d, ifelse(r[,-1] >= 0, 0, r[,-1]))
?
Tamas
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html