0 votes
1 view
in R Programming by (43.2k points)

I want to have a user-defined function that will return the first integer of a subset of a vector so that the values of the subset are unique, increasing by 1, and of a detailed length.

For example, using the input data:

v <- c(3, 4, 5, 6, 15, 16, 25, 26, 27)

l <- 3

The feasible subset of the vector would be:

c(3, 4, 5)

c(4, 5, 6)

c(25, 26, 27)

and I try to get the function to choose one of these at random and return the first/lowest number, which is either 3, 4, or 25.

1 Answer

0 votes
by (92.8k points)

I can suggest you use cgwtools::seqle as this is like rle() but you can define the desired increment in a run. Something like seqle(x, incr = 0,..) is the same as rle(x)

After that, just grab the run lengths and the starting values from the result.

If you want to know more about R then do refer to the R programming course.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...