Created
January 22, 2016 17:48
-
-
Save Rekyt/c256f96f5d416868a7c5 to your computer and use it in GitHub Desktop.
Function that has a biased selection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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