Skip to content

Instantly share code, notes, and snippets.

@Rekyt
Created January 22, 2016 17:48
Show Gist options
  • Select an option

  • Save Rekyt/c256f96f5d416868a7c5 to your computer and use it in GitHub Desktop.

Select an option

Save Rekyt/c256f96f5d416868a7c5 to your computer and use it in GitHub Desktop.
Function that has a biased selection
# Example of a function that creates a biased distribution
# Packages --------------------------------------------------------------------
library(ggplot2)
# Constants -------------------------------------------------------------------
data_size = 10000
test_index = 10
# Data Evaluation -------------------------------------------------------------
# Generates a vector of random numbers
vec = runif(data_size)*test_index - 1
# Apply 'max' function over the vector
vec = sapply(vec, function(x) max(x, 1))
df = data.frame(value = vec)
# Plot ------------------------------------------------------------------------
p = ggplot(df, aes(x = value)) +
geom_histogram()
p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment