Displaying 1 result from an estimated 1 matches for "x2high".
Did you mean:
x1high
2010 Feb 04
1
replace a for loop with lapply or relative
...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)
d[,4:6]=data.frame(sapply(d,function(v)as.numeric(v>=quantile(v,0.9))));
names(d)[4:6]=c('x1high','x2high','x3high')
head(d)
for (i in
1:3){print(do.call(rbind,by(d[,i],d[,i+3],function(x)(c(min(x),max(x))))))}
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...