getting-started.RmdRelational databases rely on well-structured data to reduce redundancy, ensure consistency, and support efficient analysis. Unfortunately, many real-world datasets are messy, with unclear keys and violations of normalization principles.
NormForm is an R package designed to address this gap by
providing tools to:
These tools help bridge the gap between theoretical concepts and practical data analysis.
When working with real data, determining whether a dataset satisfies normalization conditions often requires manual inspection. Identifying valid keys can also become computationally expensive as the number of variables increases.
NormForm simplifies these tasks by automating:
This makes the package especially useful for students, researchers, and analysts working with relational data in R.
This vignette uses three example datasets included in the package:
college: 1372 observations, 29 variables, includes a
unique identifier (unitid)auto: 398 observations, 11 variables, no obvious unique
identifiercounties: 100 observations, 18 variables, includes a
unique identifier (RN)The is_key() function tests whether a column or set of
columns uniquely identifies each row in a dataset.
is_key(college, "unitid")
#> [1] TRUEThis returns TRUE if the column is a valid key.
You can also test combinations of columns:
To automatically search for keys, use find_keys():
find_keys(auto, max_size = 2)
#> NULLThis function:
The max_size argument controls the maximum number of
columns considered in combinations.
A dataset is in first normal form if:
first_normal(college)
#> [1] "TRUE"If the dataset does not satisfy these conditions, the function
returns FALSE along with a message indicating the
issue.
A dataset is in second normal form if:
second_normal(college)
#> [1] "TRUE"For composite keys, the function checks whether any subset of the key uniquely identifies the data. If so, a partial dependency exists.
Datasets with single-column keys automatically satisfy second normal form.
A dataset is in third normal form if:
third_normal(college)
#> [1] "TRUE"Transitive dependencies occur when non-key attributes depend on other non-key attributes rather than directly on the key.
The following example demonstrates a typical workflow using
NormForm:
# Step 1: Identify candidate keys
keys <- find_keys(auto, max_size = 2)
# Step 2: Validate a candidate key
is_key(auto, keys[[1]])
#> [1] FALSE
# Step 3: Evaluate normalization
first_normal(auto)
#> [1] "FALSE: Dataset is NOT in First Normal Form, no candidate key exists"
second_normal(auto)
#> [1] "FALSE: Dataset is NOT in Second Normal Form because it is not in First Normal Form"
third_normal(auto)
#> [1] "FALSE: Dataset is NOT in Third Normal Form because it is not in Second Normal Form"This workflow allows users to move from raw data to a structured assessment of relational integrity.
NormForm provides a structured and practical approach to
evaluating relational datasets. It allows users to:
These tools improve data organization and make database normalization concepts easier to apply in real-world analysis.