ls=gsub("\\D+","",Lines1[indx])
res
A.K.
- Original Message -
From: Nico Met
To: R help
Cc:
Sent: Wednesday, April 23, 2014 3:28 PM
Subject: [R] Formatting with strings
Dear all, I have object where I stored clusters in the following manner:
---CLUSTER 1 ---
3
4
5
6
-
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
Dear all, I have object where I stored clusters in the following manner:
---CLUSTER 1 ---
3
4
5
6
---CLUSTER 2 ---
9
10
8
11
Now want to format the data in the following way:
Object Cluster
31
41
51
61
9 2
10 2
8
4 matches
Mail list logo