diff --git a/docs/_static/code/simil.R b/docs/_static/code/simil.R index 2f3124f8..5455209a 100644 --- a/docs/_static/code/simil.R +++ b/docs/_static/code/simil.R @@ -1,38 +1,34 @@ ## -## FUNCTION simil() similarity based on data frame coocurrences +## FUNCTION simil() to compute similarity of entries in a given data frame ## (CC BY-SA 4.0) Antonio Rivero Ostoic, jaro@cas.au.dk ## -## version 0.1 (16-04-2020) +## version 0.2 (11-03-2020) ## -## Parameters -## x a data frame or a list object with vectors to compare +## INPUT AND ARGUMENTS +## x a data frame with an ID column ## att (vector) column(s) in x representing attributes ## null (optional) include NA or NULLs? ## uniq (optional) remove duplicates? ## diag.incl (optional) include entries in diagonal? + simil <- function (x, att, null, uniq, diag.incl) { - ifelse(is.data.frame(x) == FALSE, x <- as.data.frame(do.call(rbind, - x)), NA) - if (missing(att) == TRUE) { - att <- seq_len(ncol(x)) - } - else { - ifelse(is.vector(att) == TRUE, NA, stop("\"att\" must be a vector.")) - } + ifelse(missing(null) == FALSE && isTRUE(null == TRUE) == + TRUE, null <- TRUE, null <- FALSE) ifelse(missing(uniq) == FALSE && isTRUE(uniq == FALSE) == - TRUE, NA, x <- unique(x)) + TRUE, uniq <- FALSE, uniq <- TRUE) + ifelse(isTRUE(uniq == TRUE) == TRUE, x <- unique(x), NA) ifelse(is.null(x$ID) == TRUE, mat <- matrix(0L, nrow = nrow(x), ncol = nrow(x), dimnames = list(unlist(x[, 1]), unlist(x[, 1]))), mat <- matrix(0L, nrow = nrow(x), ncol = nrow(x), dimnames = list(x$ID, x$ID))) for (at in att) { ccat <- unlist(unique(x[, at])) - ifelse(missing(null) == FALSE && isTRUE(null == TRUE) == - TRUE, NA, ccat <- ccat[which(ccat != "NULL")]) + ifelse(isTRUE(null == TRUE) == TRUE, NA, ccat <- ccat[which(ccat != + "NULL")]) for (i in seq_len(length(ccat))) { mat[which(x[, at] == ccat[i]), which(x[, at] == ccat[i])] <- mat[which(x[, at] == ccat[i]), which(x[, at] == ccat[i])] + diff --git a/docs/_static/code/simil.r b/docs/_static/code/simil.r deleted file mode 100644 index 5455209a..00000000 --- a/docs/_static/code/simil.r +++ /dev/null @@ -1,43 +0,0 @@ - -## -## FUNCTION simil() to compute similarity of entries in a given data frame -## (CC BY-SA 4.0) Antonio Rivero Ostoic, jaro@cas.au.dk -## -## version 0.2 (11-03-2020) -## -## INPUT AND ARGUMENTS -## x a data frame with an ID column -## att (vector) column(s) in x representing attributes -## null (optional) include NA or NULLs? -## uniq (optional) remove duplicates? -## diag.incl (optional) include entries in diagonal? - - -simil <- -function (x, att, null, uniq, diag.incl) -{ - ifelse(missing(null) == FALSE && isTRUE(null == TRUE) == - TRUE, null <- TRUE, null <- FALSE) - ifelse(missing(uniq) == FALSE && isTRUE(uniq == FALSE) == - TRUE, uniq <- FALSE, uniq <- TRUE) - ifelse(isTRUE(uniq == TRUE) == TRUE, x <- unique(x), NA) - ifelse(is.null(x$ID) == TRUE, mat <- matrix(0L, nrow = nrow(x), - ncol = nrow(x), dimnames = list(unlist(x[, 1]), unlist(x[, - 1]))), mat <- matrix(0L, nrow = nrow(x), ncol = nrow(x), - dimnames = list(x$ID, x$ID))) - for (at in att) { - ccat <- unlist(unique(x[, at])) - ifelse(isTRUE(null == TRUE) == TRUE, NA, ccat <- ccat[which(ccat != - "NULL")]) - for (i in seq_len(length(ccat))) { - mat[which(x[, at] == ccat[i]), which(x[, at] == ccat[i])] <- mat[which(x[, - at] == ccat[i]), which(x[, at] == ccat[i])] + - 1L - } - rm(i) - } - rm(at) - ifelse(missing(diag.incl) == FALSE && isTRUE(diag.incl == - TRUE) == TRUE, NA, diag(mat) <- 0) - return(mat) -}