Skip to content

Instantly share code, notes, and snippets.

@Dysp
Created June 3, 2019 12:40
Show Gist options
  • Save Dysp/3a836b0a6be492bd83e444c89f42275e to your computer and use it in GitHub Desktop.
Save Dysp/3a836b0a6be492bd83e444c89f42275e to your computer and use it in GitHub Desktop.
> class(control)
[1] "tbl_df" "tbl" "data.frame"
# Iterate over all variables and run the plotDistribution function for them
sapply(control, plotDistribution)
plotDistribution <- function(data_points) {
if (is.numeric(data_points) && length(data_points) > 2) {
# Store length of the data points
original_length <- length(data_points)
# Remove N/A
data_points_without_na <- na.omit(data_points)
# Create plot
d <- density(data_points_without_na)
plot(d)
rug(data_points)
# Return how many N/A's were omitted
glue("{original_length - length(data_points_without_na)} N/As were omitted from the data set)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment