R Under development (unstable) (2024-09-06 r87103 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 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] -2 -1 1 -3 -1 1 -1 -3 -4 2 ... add_na: FALSE int [1:15] -2 -1 1 -3 -1 1 -1 -3 -4 2 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 6.12 All weights are 1 List of 1 $ m1: num 6.12 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 5.37 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.12 All weights are 1 List of 1 $ m1: num 6.12 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 5.37 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] -2 -1 1 -3 NA 1 NA -3 -4 2 ... 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 All weights are 1 List of 1 $ m1: num 7 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 6.01 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] 1.248 3.51 -0.396 3.003 1.236 ... add_na: FALSE num [1:15] 1.248 3.51 -0.396 3.003 1.236 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 5.24 All weights are 1 List of 1 $ m1: num 5.24 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 4.09 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 5.24 All weights are 1 List of 1 $ m1: num 5.24 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 4.09 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.248 3.51 -0.396 3.003 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 5.36 All weights are 1 List of 1 $ m1: num 5.36 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 4.02 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] 0 -1 0 -1 4 2 0 0 3 -2 ... add_na: FALSE int [1:15] 0 -1 0 -1 4 2 0 0 3 -2 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 1.78 All weights are 1 List of 1 $ m1: num 1.78 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 1.57 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 1.78 All weights are 1 List of 1 $ m1: num 1.78 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 1.57 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] 0 -1 0 -1 NA 2 NA 0 3 -2 ... 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 1.55 All weights are 1 List of 1 $ m1: num 1.55 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 1.34 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] -2.185 -4.558 0.832 -2.547 1.226 ... add_na: FALSE num [1:15] -2.185 -4.558 0.832 -2.547 1.226 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 3.49 All weights are 1 List of 1 $ m1: num 3.49 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 3.27 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 3.49 All weights are 1 List of 1 $ m1: num 3.49 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 3.27 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] -2.185 -4.558 0.832 -2.547 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 3.51 All weights are 1 List of 1 $ m1: num 3.51 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 3.19 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 1 -2 2 -3 0 4 -4 0 -1 ... add_na: FALSE int [1:15] -4 1 -2 2 -3 0 4 -4 0 -1 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 4.45 All weights are 1 List of 1 $ m1: num 4.45 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 4.45 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 4.45 All weights are 1 List of 1 $ m1: num 4.45 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 4.45 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 1 -2 2 NA 0 NA -4 0 -1 ... 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 4.45 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] -1.81 -1.11 1.57 2.71 -1.47 ... add_na: FALSE num [1:15] -1.81 -1.11 1.57 2.71 -1.47 ... na.rm: FALSE Weights are not specified (all are 1) List of 1 $ m1: num 2.09 All weights are 1 List of 1 $ m1: num 2.09 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.15 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.09 All weights are 1 List of 1 $ m1: num 2.09 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.15 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] -1.81 -1.11 1.57 2.71 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.09 All weights are 1 List of 1 $ m1: num 2.09 First weight is 5 num [1:15] 5 1 1 1 1 1 1 1 1 1 ... List of 1 $ m1: num 2.15 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.48 0.10 0.57