On Jun 25, 2010, at 5:43 AM, Dennis Murphy wrote:
Hi:
Here's one approach:
x <- rep(c(1,2,1,3,5), each=5)
rle(x)
Run Length Encoding
lengths: int [1:5] 5 5 5 5 5
values : num [1:5] 1 2 1 3 5
table(rle(x)$values)
1 2 3 5
2 1 1 1
unname(table(rle(x)$values))[1]
[1] 2
This method doe
Hi:
Here's one approach:
> x <- rep(c(1,2,1,3,5), each=5)
> rle(x)
Run Length Encoding
lengths: int [1:5] 5 5 5 5 5
values : num [1:5] 1 2 1 3 5
> table(rle(x)$values)
1 2 3 5
2 1 1 1
> unname(table(rle(x)$values))[1]
[1] 2
HTH,
Dennis
On Fri, Jun 25, 2010 at 2:30 AM, Muhammad Rahiz <
muha
Hi all,
I'd like to find how many sets of 1s there are in the following example;
x <- rep(c(1,2,1,3,5), each=5)
I know that there are two sets of 1s, visually. Any function in R that
allows me to automate the process?
Thanks.
Muhammad
__
R-help@
3 matches
Mail list logo