cmp_cts: Compare counts of a list of dataframes

View source: R/cmp_other.R

cmp_ctsR Documentation

Compare counts of a list of dataframes

Description

Compare counts of a list of dataframes

Usage

cmp_cts(l, id = "id", include_ids = FALSE)

Arguments

l

List of dataframes.

id

name of the key variable in the dataframes.

include_ids

Logical denoting whether a list column of the ids should be included in the results. The ids in the list show at which values of id the variable var contains the numeric value nv1 or character (string) value cv1.

Value

Dataframe consisting of columns var, val, ..., vallab1, vallab2, ..., & n, containing a comparison of the counts of variable values (and their respective value labels) of the two dataframes in long format. nv_differ or cv_differ & vallabs_differ are logical columns indicating if all values / value labels are equal.

Examples

# load spss data
path <- system.file("examples", "iris.sav", package = "haven")
df1 <- haven::read_sav(path) %>%
  # add id column
  tibble::rownames_to_column("id")

# create a modified copy:
df2 <- df1
df2[1, "Species"] <- 2

# compare the dataframes counts:
cmp_cts(list(df1, df2))
# compare the dataframes and only show the counts where values have changed:
cmp_cts(list(df1, df2)) %>% dplyr::filter(nv1 != nv2)

# Create another modified copy
df3 <- df2
df3[2, "Species"] <- 3

# compare the dataframes counts:
l <- list(df1, df2, df3)
cmp <- cmp_cts(l)
cmp

# compare the dataframes and only show the counts where values have changed:
cmp %>% dplyr::filter(!(nv1 == nv2 & nv2 == nv3))


urswilke/tablab documentation built on Oct. 17, 2022, 8:19 p.m.