File: setup.R

package info (click to toggle)
r-bioc-sparsematrixstats 1.2.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,052 kB
  • sloc: cpp: 1,332; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 723 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


make_matrix <- function(nrow, ncol, frac_zero = 0.8, frac_na = 0){
  n_total <- ncol * nrow
  data <- rnorm(n = n_total, mean=0, sd=10)
  data[sample(seq_len(n_total), size = round(n_total * frac_zero))] <- 0
  data[sample(seq_len(n_total), size = round(n_total * frac_na))] <- NA
  matrix(data, nrow=nrow, ncol=ncol)
}

make_matrix_with_all_features <- function(nrow, ncol){
  if(ncol < 8){
    stop("Too few columns")
  }
  mat <- make_matrix(nrow, ncol, frac_zero = 0.8)
  # All observed
  mat[,1] <- rnorm(nrow)
  # All zero
  mat[,2] <- 0
  # Some missing
  mat[7, 3] <- NA
  # All missing
  mat[,4] <- NA
  # Some infinite
  mat[1, 5] <- Inf
  mat[3, 6] <- -Inf
  # Some with known value
  mat[1, 7] <- 42

  mat
}