R/generate_random_data.R

Defines functions generate_random_data2 generate_random_data

#' @export
generate_random_data <- function(N, labels, sd=100) {
  f <- function(x) {
    which <- which(x == labels)
    if(which == 1) {
      1000
    } else if(which == 5) {
      400
    } else {
      500
    }
  }
  labs <- sample(labels, N, replace = TRUE)
  values <- sapply(labs, function(lab) round(rnorm(1, mean = f(lab), sd=sd))*100)
  data.frame(id=seq_len(N), value=values, label=labs, stringsAsFactors = FALSE)
}

#' @export
generate_random_data2 <- function(N, labels, sd=1) {
  labs <- sample(labels, N, replace = TRUE)
  values <- sapply(labs, function(lab) rnorm(1, mean = nchar(lab), sd=sd))
  data.frame(id=seq_len(N), value=values, label=labs, stringsAsFactors = FALSE)
}
hoxo-m/mergetree documentation built on May 16, 2017, 12:56 a.m.