Hi,
You could try:
Lines1 <- readLines(textConnection("---CLUSTER 1 ---
3
4
5
6
---CLUSTER 2 ---
9
10
8
11"))
indx <- grepl("CLUSTER", Lines1)
res <- data.frame(Object=Lines1[!indx], Cluster=
as.numeric(as.character(factor(cumsum(indx)[-which(indx)],
labels=gsub("\\D+","",Lines1[indx])
re
Many thanks Jim. It works for my large data set!
Best Regards
Nico
On Wed, Apr 23, 2014 at 1:45 PM, jim holtman wrote:
> try this:
>
> > x <- readLines(textConnection("---CLUSTER 1 ---
> + 3
> + 4
> + 5
> + 6
> + ---CLUSTER 2 ---
> + 9
> + 10
> + 8
> + 11"))
> >
> > # create a list of where t
try this:
> x <- readLines(textConnection("---CLUSTER 1 ---
+ 3
+ 4
+ 5
+ 6
+ ---CLUSTER 2 ---
+ 9
+ 10
+ 8
+ 11"))
>
> # create a list of where the 'clusters' are
> clust <- c(grep("CLUSTER", x), length(x) + 1L)
>
> # get size of each cluster
> clustSize <- diff(clust) - 1L
>
> # get cluster numb
3 matches
Mail list logo