From: Huntsinger, Reid <reid_huntsinger_at_merck.com>

Date: Sat 21 May 2005 - 02:16:56 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat May 21 02:50:11 2005

Date: Sat 21 May 2005 - 02:16:56 EST

You could use apply as well, like

> apply(z,1,function(x) pmin(x,top))

-----Original Message-----

From: r-help-bounces@stat.math.ethz.ch

[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Clark Allan
Sent: Friday, May 20, 2005 10:01 AM

To: r-help@stat.math.ethz.ch

Subject: [R] R: looping

i have a simple question. code is displayed below.

how can i use a vectorised command in order to do this (ie replace the loop)? (ie apply, lapply, sweep, etc)

z<-matrix(c(1:9),3,3)

top<-c(1.5,5.5,9)

for (i in 1:3) z[z[,i]>top[i]]<-top[i]

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat May 21 02:50:11 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:31:58 EST
*