jcount() tells jstats to treat one or more variables as count
variables (non-negative whole-number tallies). A count is numeric-like – it
passes wherever a numeric variable does and shows mean/median in
jscreen – and additionally carries count semantics: it is the
asserted signal behind the count-regression caveat in jlm and
the routing target for future count-model functions. Unlike the structural
guess, jcount accepts counts of any range, including those outside the
automatic small-range detection (e.g. a 0-30 victimization count).
Arguments
- data
A data frame, or omitted to use the
jusedefault.jcount(NULL)clears the count registrations on thejusedefault frame (or, with no default set, the only frame that carries them; if several do, it asks rather than wiping all).jcount(data, NULL)clears that one frame's count registrations. Called with no arguments,jcount()lists the session's numeric and count registrations. Registrations are stored under the data frame's name, so it is given as a name (or as a place such aslst$d); an expression that builds one is refused, with the two lines that name it first. TheNULLandremove = TRUEforms work on a name whose data frame has since been removed.- ...
One or more unquoted variable names to register. The registration applies to numeric variables and to haven-labelled variables that hold numbers. Any other type is refused, and none of the call's variables is then registered: convert a factor or a text variable to numbers first with
jencode.- remove
Logical; if
TRUE, remove the count registration for the named variables instead of adding it.- clear.all
Logical; if
TRUE, clear count registrations on every data frame that carries them.
Details
A variable carries exactly one registered intent at a time, so registering it as a count clears any prior dummy or numeric registration. Registration changes no data and assigns nothing. It is stored for the session, keyed by the data frame's name; save the data frame in R format (.rds) to keep it across sessions.
Examples
df <- data.frame(arrests = c(0, 1, 2, 0, 3, 1, 0, 12),
age = c(21, 34, 45, 29, 51, 38, 26, 60))
jcount(df, arrests) # treat as a count (here 0-12)
#> Count registration set for 'arrests' in df.
#> Note: this registration is stored for this session only.
#> To keep it across sessions, save the data frame in R format (.rds):
#> jsave(df, "df.rds")
#>
#> Next session, load that file to restore the registration:
#> jload("df.rds")
jcount(data = df, arrests) # the data frame by name
#> Count registration set for 'arrests' in df.
#> Note: this registration is stored for this session only.
#> To keep it across sessions, save the data frame in R format (.rds):
#> jsave(df, "df.rds")
#>
#> Next session, load that file to restore the registration:
#> jload("df.rds")
juse(df); jcount(arrests); juse(NULL) # or the juse() default
#> Default data frame set to: df
#> Using default data frame: df
#> Count registration set for 'arrests' in df.
#> Note: this registration is stored for this session only.
#> To keep it across sessions, save the data frame in R format (.rds):
#> jsave(df, "df.rds")
#>
#> Next session, load that file to restore the registration:
#> jload("df.rds")
#> Default data frame cleared.
jcount(df, arrests, remove = TRUE)
#> Count registration removed for 'arrests' in df.
jcount() # list all registrations
#> No variable registrations in this session.
jcount(df, NULL) # clear df's count registrations
#> No count registrations to clear for df.
jcount(clear.all = TRUE) # clear every frame's count registrations
#> No count registrations to clear.