census.calc: Carry out calculations on a subset of variables in a specific...

Description Usage Arguments Details Value

View source: R/HexSimR.R

Description

census.calc carries out calculations indicated with the argument bin.f. For example, this will be needed when trait are sub-classes and there is the need to sum a subset of them (e.g. traits are divided by gender and age and the user wants to have the total by gender) or calculate a proportion (e.g. sex-ratio or over the total). Therefore, typically, these operations will be sums, subtractions, divisions or multiplications. However, bin.f can take any function that it is compatible with Reduce() (default is "+").

The existing census file will be overwritten with the new census file, which will include the new variable.

The subset of data to be used by bin.f is indicated with headers. This argument takes a character vector with the headers of the census files. These have to match exactly the headers in the census file (including spaces). headers is internally modified with make.names() to guarantee that names are syntactically valid. Therefore, a character vector where the headers were already modified and would match the results of make.names() is also acceptable.

The argument var.name is the name of the new variable being calculated. If none is passed, then, by default, census.calc will paste together the names passed with headers separated by the operator passed with bin.f. If bin.f is a function (i.e. a R object of class 'function'), the default behaviour will fail and an error is reported. In this case, the user have to pass a valid var.name. It is recommended to use letters, numbers and the dot or underline ("_") characters, to start with a letter or the dot not followed by a number.

Usage

1
2
3
4
5
6
7
8
9
census.calc(
  path.results = NULL,
  ncensus,
  headers,
  var.name = NULL,
  bin.f = "+",
  scenarios = "all",
  verbose = FALSE
)

Arguments

path.results

The path to the 'Results' folder

ncensus

The census number to be processed

headers

A character vector matching exactly the headers of the census file columns that are to be used by bin.f

var.name

A character vector to name the new variable. Mandatory if bin.f is of class function. See details.

bin.f

A character vector to pass the binary function to be applied to the columns identified by headers (Default: "+")

scenarios

A character vector with the scenarios to be processed or "all"

verbose

Should progress be printed in the console? Default: FALSE

Details

If more then one calculations needs to be performed, of the same calculations needs to be performed on different groups of variables (headers), then census.calc needs to be run multiple times.

Value

Save census file to disk and return a list with the new census files


carlopacioni/HexSimR documentation built on Nov. 28, 2020, 4:12 p.m.