Skip to content

Commit

Permalink
set current starting value before entering loop
Browse files Browse the repository at this point in the history
  • Loading branch information
addisonklinke committed Apr 17, 2020
1 parent c3c1b11 commit 52cc27f
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions R/CountCycles.numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,19 @@ CountCycles.numeric <- function(x) {
positions <- 1:length(x)
start <- 1
remaining <- TRUE
current <- NULL
current <- positions[1:3]
cycles <- matrix(0, nrow = floor(length(x) - 1), ncol = 3)
cyc <- 1

while (TRUE) {

# Ensure at least 3 points are available
if (length(current) < 3) {
if (!is.null(current)) {
following <- positions[!(positions %in% current)]
if (length(following) > 0) {
current <- c(current, following[1])
} else {
break
}
following <- positions[!(positions %in% current)]
if (length(following) > 0) {
current <- c(current, following[1])
} else {
current <- positions[1:3]
break
}
}

Expand Down

0 comments on commit 52cc27f

Please sign in to comment.