Description Usage Arguments Value Examples
Look for "primary keys" of a data frame. The primary key is a variable (or combination of variables) that uniquely identify all rows.
1 |
df |
A data frame in which to find the primary key. |
varz |
A numeric or character vector representing the candidate columns or
variable names to consider for membership in the primary key, default
is to include all variables, |
A list with two elements, npk
an integer giving the number
of variables that make up the primary key, and k
a list of character
vectors) identifying the variable names that make up the primary key.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | mydat1 <- data.frame(
group=c("a", "a", "a", "b", "b", "c", "c", "d", "d"),
id=1:9,
value=rnorm(9))
mydat2 <- data.frame(
group=c("a", "a", "a", "b", "b", "c", "c", "d", "d"),
id=c(1:3, 1:2, 1:2, 1:2),
value=rnorm(9))
mydat3 <- data.frame(
group=c("a", "a", "a", "b", "b", "c", "c", "d", "d"),
name=c("ax", "ax", "ax", "be", "be", "cat", "cat", "dog", "dog"),
id=c(1:3, 1:2, 1:2, 1:2),
value=rnorm(9))
# primary key made up of one variable
primKey(mydat1[, c("group", "id")])
# primary key made up of two variables
primKey(mydat2[, c("group", "id")])
# two primary keys, each made up of two variables
primKey(mydat3[, c("group", "name", "id")])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.