Learn R Programming

gsignal (version 0.3-1)

clustersegment: Cluster Segments

Description

Calculate boundary indexes of clusters of 1<U+2019>s.

Usage

clustersegment(x)

Arguments

x

input data, specified as a numeric vector or matrix, coerced to contain only 0's and 1's, i.e., every nonzero element in x will be replaced by 1.

Value

A list of size nr, where nr is the number of rows in x. Each element of the list contains a matrix with two rows. The first row is the initial index of a sequence of 1<U+2019>s and the second row is the end index of that sequence.

Details

The function calculates the initial index and end index of sequences of 1's rising and falling phases of the signal in x. The clusters are sought in the rows of the array x. The function works by finding the indexes of jumps between consecutive values in the rows of x.

Examples

Run this code
# NOT RUN {
(x <- c(0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1))
(ranges <- clustersegment(x))
# The first sequence of 1's in x lies in the interval
(r <- ranges[1,1]:ranges[2,1])

x <- matrix(as.numeric(runif(30) > 0.4), 3, 10)
ranges <- clustersegment(x)

x <- c(0, 1.2, 3, -8, 0)
ranges <- clustersegment(x)

# }

Run the code above in your browser using DataLab