R: Obtaining a Sample and putting it into a Group -


so i've got random sample standard normal distribution, (call x) had order it, , put ordered vector 10 groups first group contains 10 lowest , on. have create new vector such in order of x, value in y group number value of x in. i.e first 3 values in x in groups 2,5 & 4 respectively, first 3 values in y 2,5,4... can give assistance code , see i've gone wrong?

x<-rnorm(100, mean=0, sd =1) y<-(c(x)) datart<-x[order(x)] datart v1<-datart[1:10] v2<-datart[11:20] v3<-datart[21:30] v4<-datart[31:40] v5<-datart[41:50] v6<-datart[51:60] v7<-datart[61:70] v8<-datart[71:80] v9<-datart[81:90] v10<-datart[91:100] (i in y) {     if (i<-v1) print(1)     else if (i<-v2) print(2)     else if (i<-ve) print(3)     else if (i<-v4) print(4)     else if (i<-v5) print(5)     else if (i<-v6) print(6)     else if (i<-v7) print(7)     else if (i<-v8) print(8)     else if (i<-v9) print(9)     else if (i<-v10) print(10) } 

here one-liner, adapt different number of groups or different group sizes.

x   <- rnorm(100) out <- rep(1:10, each = 10)[order(order(x))] 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -