R Under development (unstable) (2023-11-06 r85483 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library("matrixStats") > > fcns <- list( + weightedVar = weightedVar, + weightedSd = weightedSd, + weightedMad = weightedMad + ) > > for (name in names(fcns)) { + cat(sprintf("%s()...\n", name)) + fcn <- fcns[[name]] + + for (mode in c("integer", "double")) { + cat("mode: ", mode, "\n", sep = "") + n <- 15L + x <- runif(n, min = -5, max = 5) + storage.mode(x) <- mode + str(x) + + for (add_na in c(FALSE, TRUE)) { + cat("add_na: ", add_na, "\n", sep = "") + if (add_na) { + x[c(5, 7)] <- NA + } + str(x) + + for (na.rm in c(FALSE, TRUE)) { + cat("na.rm: ", na.rm, "\n", sep = "") + + cat("Weights are not specified (all are 1)\n") + m1 <- fcn(x, na.rm = na.rm) + str(list(m1 = m1)) + + cat("All weights are 1\n") + w <- rep(1, times = n) + m1 <- fcn(x, w, na.rm = na.rm) + str(list(m1 = m1)) + + cat("First weight is 5\n") + # Pull the mean towards zero + w[1] <- 5 + str(w) + m1 <- fcn(x, w, na.rm = na.rm) + str(list(m1 = m1)) + + cat("All weights are 0\n") + # All weights set to zero + w <- rep(0, times = n) + m1 <- fcn(x, w, na.rm = na.rm) + str(list(m1 = m1)) + + cat("First weight is 8.5\n") + # Put even more weight on the zero + w[1] <- 8.5 + m1 <- fcn(x, w, na.rm = na.rm) + str(list(m1 = m1)) + + cat("First weight is Inf\n") + # All weight on the first value + w[1] <- Inf + m1 <- fcn(x, w, na.rm = na.rm) + str(list(m1 = m1)) + + cat("Last weight is Inf\n") + # All weight on the last value + w[1] <- 1 + w[n] <- Inf + m1 <- fcn(x, w, na.rm = na.rm) + str(list(m1 = m1)) + + cat("Last weight is NA\n") + # All weight on the last value + w[1] <- 1 + w[n] <- NA_real_ + m1 <- fcn(x, w, na.rm = na.rm) + str(list(m1 = m1)) + } # for (na.rm ...) + } # for (add_na ...) + } # for (mode ...) + + cat(sprintf("%s()...DONE\n", name)) + } # for (name ...) weightedVar()... mode: integer int [1:15] 3 1 4 -3 0 -1 1 -4 -3 3 ... add_na: FALSE int [1:15] 3 1 4 -3 0 -1 1 -4 -3 3 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 6.35 All weights are 1 List of 1 $ m1: num 6.35 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 6.45 All weights are 0 List of 1 $ m1: int NA First weight is 8.5 List of 1 $ m1: int NA First weight is Inf List of 1 $ m1: int NA Last weight is Inf List of 1 $ m1: int NA Last weight is NA List of 1 $ m1: int NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 6.35 All weights are 1 List of 1 $ m1: num 6.35 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 6.45 All weights are 0 List of 1 $ m1: int NA First weight is 8.5 List of 1 $ m1: int NA First weight is Inf List of 1 $ m1: int NA Last weight is Inf List of 1 $ m1: int NA Last weight is NA List of 1 $ m1: int NA add_na: TRUE int [1:15] 3 1 4 -3 NA -1 NA -4 -3 3 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: int NA All weights are 1 List of 1 $ m1: int NA First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: int NA All weights are 0 List of 1 $ m1: int NA First weight is 8.5 List of 1 $ m1: int NA First weight is Inf List of 1 $ m1: int NA Last weight is Inf List of 1 $ m1: int NA Last weight is NA List of 1 $ m1: int NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 7.33 All weights are 1 List of 1 $ m1: num 7.33 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 7.22 All weights are 0 List of 1 $ m1: int NA First weight is 8.5 List of 1 $ m1: int NA First weight is Inf List of 1 $ m1: int NA Last weight is Inf List of 1 $ m1: int NA Last weight is NA List of 1 $ m1: int NA mode: double num [1:15] 4.9 3.5 -3.46 2 -2.68 ... add_na: FALSE num [1:15] 4.9 3.5 -3.46 2 -2.68 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 9.13 All weights are 1 List of 1 $ m1: num 9.13 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 10.9 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 9.13 All weights are 1 List of 1 $ m1: num 9.13 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 10.9 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA add_na: TRUE num [1:15] 4.9 3.5 -3.46 2 NA ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num NA All weights are 1 List of 1 $ m1: num NA First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num NA All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 7.64 All weights are 1 List of 1 $ m1: num 7.64 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 8.9 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA weightedVar()...DONE weightedSd()... mode: integer int [1:15] 3 0 -2 3 -2 0 -2 4 4 -3 ... add_na: FALSE int [1:15] 3 0 -2 3 -2 0 -2 4 4 -3 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 2.78 All weights are 1 List of 1 $ m1: num 2.78 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.72 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 2.78 All weights are 1 List of 1 $ m1: num 2.78 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.72 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA add_na: TRUE int [1:15] 3 0 -2 3 NA 0 NA 4 4 -3 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num NA All weights are 1 List of 1 $ m1: num NA First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num NA All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 2.85 All weights are 1 List of 1 $ m1: num 2.85 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.69 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA mode: double num [1:15] -1.44 -1.35 3.09 2.38 3.96 ... add_na: FALSE num [1:15] -1.44 -1.35 3.09 2.38 3.96 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 2.98 All weights are 1 List of 1 $ m1: num 2.98 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.7 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 2.98 All weights are 1 List of 1 $ m1: num 2.98 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.7 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA add_na: TRUE num [1:15] -1.44 -1.35 3.09 2.38 NA ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num NA All weights are 1 List of 1 $ m1: num NA First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num NA All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 2.83 All weights are 1 List of 1 $ m1: num 2.83 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.49 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num NA First weight is Inf List of 1 $ m1: num NA Last weight is Inf List of 1 $ m1: num NA Last weight is NA List of 1 $ m1: num NA weightedSd()...DONE weightedMad()... mode: integer int [1:15] -4 0 0 -4 -1 3 -1 -2 -1 -3 ... add_na: FALSE int [1:15] -4 0 0 -4 -1 3 -1 -2 -1 -3 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 1.48 All weights are 1 List of 1 $ m1: num 1.48 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.97 All weights are 0 List of 1 $ m1: int NA First weight is 8.5 List of 1 $ m1: int 0 First weight is Inf List of 1 $ m1: int 0 Last weight is Inf List of 1 $ m1: int 0 Last weight is NA List of 1 $ m1: int NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 1.48 All weights are 1 List of 1 $ m1: num 1.48 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.97 All weights are 0 List of 1 $ m1: int NA First weight is 8.5 List of 1 $ m1: int 0 First weight is Inf List of 1 $ m1: int 0 Last weight is Inf List of 1 $ m1: int 0 Last weight is NA List of 1 $ m1: int NA add_na: TRUE int [1:15] -4 0 0 -4 NA 3 NA -2 -1 -3 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num NA All weights are 1 List of 1 $ m1: int NA First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: int NA All weights are 0 List of 1 $ m1: int NA First weight is 8.5 List of 1 $ m1: int 0 First weight is Inf List of 1 $ m1: int 0 Last weight is Inf List of 1 $ m1: int 0 Last weight is NA List of 1 $ m1: int NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 2.97 All weights are 1 List of 1 $ m1: num 2.97 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.97 All weights are 0 List of 1 $ m1: int NA First weight is 8.5 List of 1 $ m1: int 0 First weight is Inf List of 1 $ m1: int 0 Last weight is Inf List of 1 $ m1: int 0 Last weight is NA List of 1 $ m1: int NA mode: double num [1:15] 4.388 3.543 -2.827 0.644 2.306 ... add_na: FALSE num [1:15] 4.388 3.543 -2.827 0.644 2.306 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 2.53 All weights are 1 List of 1 $ m1: num 2.53 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 3.63 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num 0 First weight is Inf List of 1 $ m1: num 0 Last weight is Inf List of 1 $ m1: num 0 Last weight is NA List of 1 $ m1: num NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 2.53 All weights are 1 List of 1 $ m1: num 2.53 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 3.63 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num 0 First weight is Inf List of 1 $ m1: num 0 Last weight is Inf List of 1 $ m1: num 0 Last weight is NA List of 1 $ m1: num NA add_na: TRUE num [1:15] 4.388 3.543 -2.827 0.644 NA ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num NA All weights are 1 List of 1 $ m1: num NA First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num NA All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num 0 First weight is Inf List of 1 $ m1: num 0 Last weight is Inf List of 1 $ m1: num 0 Last weight is NA List of 1 $ m1: num NA na.rm: TRUE Weights are not specified (all are 1) List of 1 $ m1: num 2.45 All weights are 1 List of 1 $ m1: num 2.45 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 3.73 All weights are 0 List of 1 $ m1: num NA First weight is 8.5 List of 1 $ m1: num 0 First weight is Inf List of 1 $ m1: num 0 Last weight is Inf List of 1 $ m1: num 0 Last weight is NA List of 1 $ m1: num NA weightedMad()...DONE > > proc.time() user system elapsed 0.32 0.03 0.34