View source: R/ejscreen.acs.calc.R
ejscreen.acs.calc | R Documentation |
Use specified formulas to create calculated, derived variables such as percent low income. Relies upon analyze.stuff::calc.fields() from analyze.stuff package.
ejscreen.acs.calc(
bg,
folder = getwd(),
keep.old,
keep.new,
formulafile,
formulas
)
bg |
Data.frame of raw demographic data counts, and environmental indicators, for each block group, such as population or number of Hispanics. |
folder |
Default is getwd(). Specifies path for where to read from (if formulafile specified) and write to. |
keep.old |
Vector of variables names from names(bg), indicating which to return (retain, not drop). Default is to keep only the ones that match the list of default names in this code. Or this can be simply 'all' which means keep all input fields. |
keep.new |
Vector of variables names of new created variables, indicating which to return (retain, not drop). Default is to keep a specific list of fields (see source code). Or this can be simply 'all' which means keep all new fields. |
formulafile |
Name of optional csv file with column called formula, providing R syntax formulas as character fields.
If not specified, function gets this from data(ejscreenformulas).
Example of one formula: 'pctunder5 <- ifelse( pop==0,0, under5/pop)'
Use a result of zero in cases where the denominator is zero, to avoid division by zero.
For example, the formula |
formulas |
Options vector of formulas as character strings that contain R statements in the form "var1 <- var2 + var3" for example. Either formulafile or formulas can be specified (or neither) but not both (error). Formulas should be in the same format as a formulafile field or the contents of ejscreenformulas (via data(ejscreenformulas) or lazy loading like x <- ejscreenformulas). |
Returns a data.frame with some or all of input fields (those in keep.old), plus calculated new fields (those in keep.new).
set.seed(99)
envirodata=data.frame(FIPS=analyze.stuff::lead.zeroes(1:1000, 12),
air=rlnorm(1000), water=rlnorm(1000)*5, stringsAsFactors=FALSE)
demogdata=data.frame(FIPS=analyze.stuff::lead.zeroes(1:1000, 12),
pop=rnorm(n=1000, mean=1400, sd=200), mins=runif(1000, 0, 800),
num2pov=runif(1000, 0,500), stringsAsFactors=FALSE)
demogdata$povknownratio <- demogdata$pop
x=ejscreen.acs.calc(bg=demogdata)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.