[R] R help again..SORRY!

arun smartpink111 at yahoo.com
Sat Aug 31 18:20:50 CEST 2013



HI,

May be this helps:

library(Ckmeans.1d.dp)
 set.seed(24)
 RanNum1<-runif(20,9,12)
Ck1<-Ckmeans.1d.dp(RanNum1,4)
 plot(RanNum1,col=Ck1$cluster)
 abline(h=Ck1$centers,col=1:4,pch=8,cex=2)
 Ck1$cluster
# [1] 2 2 3 3 3 4 2 4 4 2 3 2 3 3 2 4 2 1 3 1
which(Ck1$cluster==2,arr.ind=T) 
#[1]  1  2  7 10 12 15 17


#
res<-lapply(unique(Ck1$cluster),function(x) which(Ck1$cluster==x,arr.ind=T))
 names(res)<- unique(Ck1$cluster)
 res
#$`2`
#[1]  1  2  7 10 12 15 17
#
#$`3`
#[1]  3  4  5 11 13 14 19
#
#$`4`
#[1]  6  8  9 16
#
#$`1`
#[1] 18 20



A.K.



Hello guys, sorry to bother you guys again but was wondering if I'm doing this correctly. I seem to have run into trouble. 



I've done the first two parts 


But I can't seem to understand how to do the last part with the which() function. 

This is what I came up with 


Am I on the right track? Or am I using this which() function incorrectly?   




More information about the R-help mailing list