Last chance! 50% off unlimited learning
Sale ends in
.do_if
/.modify_if
can be
very slow.
.modify(expr)
.modify_if(cond, expr)
.do_if(cond, expr)
.compute(expr)
.with(expr, ...)
.val_lab(...)
.var_lab(...)
.set_var_lab(x, ...)
.set_val_lab(x, ...)
.add_val_lab(x, ...)
.if_val(x, ...)
.recode(x, ...)
.fre(...)
.cro(...)
.cro_cpct(...)
.cro_rpct(...)
.cro_tpct(...)
.cro_mean(...)
.cro_sum(...)
.cro_median(...)
.cro_fun(...)
.cro_fun_df(...)
.set(varnames, value = NA)
varnames
will be expanded as with subst..modify
Add and modify variables inside default data.frame. See
modify.
.compute
Shortcut for .modify
. Name is inspired by
SPSS COMPUTE operator. See modify.
.modify_if
Add and modify variables inside subset of default
data.frame. See modify_if.
.do_if
Shortcut for .modify_if
. Name is inspired by
SPSS DO IF operator. See modify_if.
.where
Leave subset of default data.frame which meet
condition. See where, subset.
.set_var_lab
Set variable label in the default data.frame. See
set_var_lab.
.set_val_lab
Set value labels for variable in the default
data.frame. See set_val_lab.
.add_val_lab
Add value labels for variable in the default
data.frame. See add_val_lab.
.if_val
Change, rearrange or consolidate the values of an existing
variable inside default data.frame. See if_val.
.recode
Shortcut for .if_val
. Name is inspired by
SPSS RECODE. See if_val.
.set
Set variables values in the default dataset with given
names filled with value
. It is possible to set multiple variables at
once. Expressions inside backticks in varnames
will be expanded as
with subst. set
(without dot) is also available inside
.compute
, .modify
, .modify_if
, .do_if
,
modify, modify_if. Other functions:
.var_lab
Return variable label from default dataset. See
var_lab.
.val_lab
Return value labels from default dataset. See
val_lab.
.fre
Simple frequencies of variable in the default
data.frame. See fre.
.cro
/.cro_cpct
/.cro_rpct
/.cro_tpct
Simple
crosstabulations of variable in the default data.frame. See cro.
.cro_mean
/.cro_sum
/.cro_median
/.cro_fun
/.cro_fun_df
Simple crosstabulations of variable in the default data.frame. See
cro_fun.
.with
Evaluate arbitrary expression in the context of
data.frame. See with.
data(mtcars)
default_dataset(mtcars) # set mtcars as default dataset
# calculate new variables
.compute({
mpg_by_am = ave(mpg, am, FUN = mean)
hi_low_mpg = ifs(mpg<mean(mpg) ~ 0, default = 1)
})
# set labels
.set_var_lab(mpg, "Miles/(US) gallon")
.set_var_lab(cyl, "Number of cylinders")
.set_var_lab(disp, "Displacement (cu.in.)")
.set_var_lab(hp, "Gross horsepower")
.set_var_lab(mpg_by_am, "Average mpg for transimission type")
.set_var_lab(hi_low_mpg, "Miles per gallon")
.set_val_lab(hi_low_mpg, ml_left("
0 Low
1 High
"))
.set_var_lab(vs, "Engine")
.set_val_lab(vs, ml_left("
0 V-engine
1 Straight engine
"))
.set_var_lab(am, "Transmission")
.set_val_lab(am, ml_left("
0 automatic
1 manual
"))
# calculate frequencies
.fre(hi_low_mpg)
.cro(cyl, hi_low_mpg)
.cro_mean(mpg, am)
.cro_mean(data.frame(mpg, disp, hp), vs)
# disable default dataset
default_dataset(NULL)
# Example of .recode
data(iris)
default_dataset(iris) # set iris as default dataset
.recode(Sepal.Length, lo %thru% median(Sepal.Length) ~ "small", other ~ "large")
.fre(Sepal.Length)
# example of .do_if
.do_if(Species == "setosa",{
Petal.Length = NA
Petal.Width = NA
})
.cro_mean(data.frame(Petal.Length, Petal.Width), Species)
# disable default dataset
default_dataset(NULL)
Run the code above in your browser using DataLab