[R] replace a for loop with lapply or relative

David Freedman 3.14david at gmail.com
Thu Feb 4 22:40:33 CET 2010

Dear helpers.
I often need to make dichotomous variables out of continuous ones (yes, I
realize the problems with throwing away much of the information), but I then
like to check the min and max of each category.  I have the following simple
code to do this that cuts each variable (x1,x2,x3) at the 90th percentile,
and then prints the min and max of each category:

d=data.frame(x1=rnorm(100),x2=runif(100)); d=transform(d,x3=x1-x2)
for (i in

Is there a way to replace the ugly for loop in the last line with some type
of apply function that would know that my continuous and indicator variable
are 3 variables apart in the dataframe?

Thanks very much
David Freedman
View this message in context: http://n4.nabble.com/replace-a-for-loop-with-lapply-or-relative-tp1469453p1469453.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list