March 2018
Beginner to intermediate
570 pages
13h 42m
English
It's common for numeric values in a column to have a natural constraint on the values that it should hold. For example, if a column represents a percent of something, we might want to check if all the values in that column are between zero and one (or 0 and 100). In assertr, we typically use the within_bounds function in conjunction with the assert verb to ensure that this is the case. For example, if we added a column to mtcars that represented the percent of the heaviest car's weight, the weight of each car is:
library(assertr)
mtcars.copy <- mtcars
mtcars.copy$Percent.Max.Wt <- round(mtcars.copy$wt /
max(mtcars.copy$wt),
2)
mtcars.copy <- assert(mtcars.copy, within_bounds(0,1),
Percent.Max.Wt)
within_bounds ...