Skip to content

Commit

Permalink
minor fixes: spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
philouail committed Oct 6, 2023
1 parent 02d1773 commit a670a98
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions R/group_standards.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,50 +75,44 @@
#'

.group_standards_iteration <- function(x, max_nstd, min_diff = 2) {

output <- vector("list")
g <- 0

while (nrow(x) > 1) {
g <- g + 1
i <- 1
group <- row.names(x)[i]

while(length(group) < max_nstd & i < nrow(x)) {
i <- i + 1
diff_table <- abs(outer(as.vector(x[group, ]), as.vector(x[i,]), "-"))
g <- g + 1
i <- 1
group <- row.names(x)[i]

if (all(diff_table > min_diff, na.rm= TRUE)) {
group <- c(group, row.names(x)[i])
}
}
x <- x[!(rownames(x) %in% group), , drop = FALSE]
output[[g]] <- group
}
if (nrow(x))
output[[g + 1]] <- row.names(x)
output[[g + 1]] <- row.names(x)

output
}


.randomize_grouping <- function(x,
max_nstd,
min_nstd,
min_diff = 2) {
max_nstd,
min_nstd,
min_diff = 2) {
n <- nrow(x)
standard_groups <- vector("list")
i <- 0
while(length(standard_groups) == 0 || any(lengths(standard_groups) <
while (length(standard_groups) == 0 || any(lengths(standard_groups) <
min_nstd)) {

i <- i +1
x <- x[sample(n), ]
standard_groups <- .group_standards_iteration(x,
max_nstd = max_nstd,
min_diff = min_diff)
if(i > n*n)
stop("all combination were tested, no possibility to fit your input requirement")
i <- i +1
x <- x[sample(n), ]
standard_groups <- .group_standards_iteration(x,
max_nstd = max_nstd,
min_diff = min_diff)
if (i > n*n)
stop("all combination were tested, no possibility to fit your input requirement")
}
standard_groups
}

0 comments on commit a670a98

Please sign in to comment.