df <- data.frame(
id = 10011:10020
, period = rep(c("2018Q1", "2018Q2", "2018Q3", "2018Q4","2018"),2)
, direction = c(rep("import",5), rep("export", 5))
, value = c(1,2,3,4,10, 3,3,3,3,13)
)
## use 'rx' to interpret 'whole' as a regular expression.
rules <- validator(
part_whole_relation(value, period, whole=rx("^\\d{4}$")
, by=direction)
)
out <- confront(df, rules, key="id")
as.data.frame(out)
Run the code above in your browser using DataLab