## --------------------------------------------------------------------------------------------------------------------- library("lessR") ## ----include=FALSE---------------------------------------------------------------------------------------------------- knitr::opts_chunk$set(fig.width=3.5, fig.height=3) ## --------------------------------------------------------------------------------------------------------------------- d <- read.table(text="Severity Description 1 Mild 4 Moderate 3 Moderate 2 Mild 1 Severe", header=TRUE, stringsAsFactors=FALSE) d ## --------------------------------------------------------------------------------------------------------------------- d <- recode(Severity, old=1:4, new=c(10,20,30,40)) d ## --------------------------------------------------------------------------------------------------------------------- d <- recode(Severity, new_vars="SevereNew", old=1:4, new=c(10,20,30,40)) ## --------------------------------------------------------------------------------------------------------------------- d <- Read("Mach4") d <- recode(c(m01:m03,m10), old=0:5, new=5:0) ## --------------------------------------------------------------------------------------------------------------------- d <- Read("Employee") newdata <- recode(Plan, old=1, new="missing") ## --------------------------------------------------------------------------------------------------------------------- head(d) ## --------------------------------------------------------------------------------------------------------------------- d <- Read("Employee") head(d) ## --------------------------------------------------------------------------------------------------------------------- d <- recode(c(Years, Salary), old="missing", new=99) head(d) ## --------------------------------------------------------------------------------------------------------------------- d <- Read("Employee") d <- d[1:12,] ## --------------------------------------------------------------------------------------------------------------------- d <- order_by(d, Gender) d ## --------------------------------------------------------------------------------------------------------------------- d <- order_by(d, c(Gender, Salary), direction=c("+", "-")) d ## --------------------------------------------------------------------------------------------------------------------- d <- order_by(d, row.names) d ## --------------------------------------------------------------------------------------------------------------------- d <- order_by(d, random) d ## --------------------------------------------------------------------------------------------------------------------- rescale(Salary) ## --------------------------------------------------------------------------------------------------------------------- names(d) d <- rename(d, Salary, AnnualSalary) names(d) ## --------------------------------------------------------------------------------------------------------------------- d <- rd("Mach4", quiet=TRUE) l <- rd("Mach4_lbl") LikertCats <- c("Strongly Disagree", "Disagree", "Slightly Disagree", "Slightly Agree", "Agree", "Strongly Agree") ## --------------------------------------------------------------------------------------------------------------------- d <- factors(m01:m20, levels=0:5, labels=LikertCats) ## --------------------------------------------------------------------------------------------------------------------- d <- factors(c(m06, m07, m20), levels=0:5, labels=LikertCats, new=TRUE) ## --------------------------------------------------------------------------------------------------------------------- l <- factors(c(m06, m07, m20), var_labels=TRUE) ## --------------------------------------------------------------------------------------------------------------------- d <- Read("Anova_rb") d ## --------------------------------------------------------------------------------------------------------------------- reshape_long(d, c("sup1", "sup2", "sup3", "sup4")) ## --------------------------------------------------------------------------------------------------------------------- reshape_long(d, sup1:sup4, group="Supplement", response="Reps", ID="Person", prefix="P") ## --------------------------------------------------------------------------------------------------------------------- d <- Read("Anova_rb") d dl <- reshape_long(d, sup1:sup4) # convert to long-form head(dl) ## --------------------------------------------------------------------------------------------------------------------- reshape_wide(dl, widen=Group, response=Response, ID=Person) ## --------------------------------------------------------------------------------------------------------------------- reshape_wide(dl, widen=Group, response=Response, ID=Person, prefix=TRUE, sep=".") ## --------------------------------------------------------------------------------------------------------------------- d <- Read("Employee", quiet=TRUE) ## --------------------------------------------------------------------------------------------------------------------- out <- train_test(d, Salary) names(out) ## --------------------------------------------------------------------------------------------------------------------- out <- train_test(d) names(out)