#' Pair Filname
#'
#'pair filename list when one string is the prefix of the other
#'
#' @param filenames
#'
#' @return
#' @export
#'
#' @examples
#' filename.pair(c('aaa', 'aaa-R', 'bbcd-C', 'bbcd'))
#' >>[1] 1 1 2 2
filename.pair <- function(filenames) {
pair <- rep(0, length(filenames))
for (i in 1:(length(filenames)-1)) {
if (pair[i] == 0) {
pair[i] <- i
pair[-(1:i)] <- i * sapply(filenames[-(1:i)], function(x) {
grepl(filenames[i], x) || grepl(x, filenames[i]) # prefix
})
}
}
if (pair[i + 1] == 0) {
pair[i + 1] <- i + 1
}
pair.factor <- as.factor(pair)
levels(pair.factor) <- as.character(seq_along(levels(pair.factor)))
return(pair.factor)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.