get_cdfs | R Documentation |
Given a data frame with at least one continuous variable and one categorical variable, we can use this function to find the empirical CDFs of any continuous variable on the data frame, optionally grouped by a categorical variable. These CDFs can then be called to return probabilities for any given x value.
get_cdfs(df)
df |
A data frame. |
function(xvar, groupby = "1")
xvar. String, name of a continuous variable over which the empirical CDF to be calculated.
groupby. String, name of a categorical variable for subsetting the data frame. Default = "1", indicating no such variable is supplied.
library(ezplot) df = data.frame(x = c(rnorm(100, 0, 3), rnorm(100, 0, 10)), gp = gl(2, 100)) CDF = get_cdfs(df) CDF_x = CDF('x') # returns a single CDF that can be called on a number CDF_x(0.23) CDFs_x_by_gp = CDF('x', 'gp') # returns a list of CDFs, one for each group sapply(CDFs_x_by_gp, function(f) f(0.23))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.