for (j in 1:n) df[,j] <- pmin( pmax( df[,j], 0 ), 1 ) should do the job.
Bendix Carstensen ---------------------- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc ---------------------- > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Monica > Palaseanu-Lovejoy > Sent: Wednesday, June 23, 2004 11:07 AM > To: [EMAIL PROTECTED] > Subject: [R] Automatic routine - help > > > Hi, > > I would like to write a little automatic routine in R, but i am a too > much of a beginner for that. I will appreciate any help > regarding this > particular problem. > > Let's suppose I have a data.frame with j columns (from 1 to n) and i > rows (from 1 to p). I would like to write a procedure which reads > every column j (j from 1 to n) and compare each value with the > interval [0,1]. If z(i,j) is less than 0, then replace z(i,j) > with 0. If z(i,j) > is greater than 1, then replace z(i,j) with 1. If z(i,j) is > inside the > interval [0,1] then don't change. In the end I would like to have a > new data.frame with the new values. > > I am not sure how complicated or long such a procedure might be, > so I will be very grateful for any help. > > Thank you in advance, > > Monica > > ______________________________________________ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
