[R] indexing a vector

morozov morozov at uclink.berkeley.edu
Thu Oct 2 19:40:45 CEST 2003


Dear All:
I'd like to know how to sort and then index a vector of floats by several 
levels in R.
For example


>x<-rnorm(100)
> MyLevels<-quantile(x,probs=c(0,.5,1))
> MyLevels
         0%         50%        100% 
-2.11978442 -0.03770613  2.00186397

next i want to replace each x[i] in x by 1,2,3 or 4 depending on which 
quantile that x[i] falls. How do I do that in a "vector" fashion?

I tried something like

>factor(x,levels=as.numeric(MyLevels))

but that doesnt work.


Thank you very much,
Vlad




More information about the R-help mailing list