# 1. Create sample source data (S_data)
S_data <- data.frame(
id = 1:10,
national_id = c("1234567890", "0987654321", "123", NA, "1112223334",
"1234567890", "5556667778", "9998887770", "12345", "4445556667"),
gender = c(1, 2, 1, 3, 2, 1, NA, 2, 1, 2), # 1=Male, 2=Female, 3=Error
age = c(25, 40, 150, 33, -5, 65, 45, 29, 70, 55),
part_a = c(10, 15, 20, 25, 30, 35, 40, 45, 50, 55),
part_b = c(5, 10, 15, 20, 25, 30, 35, 40, 45, 50),
total_parts = c(15, 25, 35, 45, 55, 65, 75, 85, 94, 105), # one error in row 9
stringsAsFactors = FALSE
)
# 2. Create sample metadata (M_data)
M_data <- data.frame(
VARIABLE = c(
"national_id",
"national_id",
"gender",
"total_parts"
),
Conformance_Rule = c(
"length_check",
"unique_check",
"category_check",
"arithmetic_check"
),
Value = c(
"10", # national_id length must be 10
"", # unique
"1 | 2", # Allowed values for gender
"part_a + part_b" # Computational rule for total_parts
),
stringsAsFactors = FALSE
)
# 3. Run the conformance check using the package's default rules
# Ensure the 'DQA' package is loaded before running
conformance_results <- conformance_check(S_data = S_data, M_data = M_data)
print(conformance_results)
Run the code above in your browser using DataLab