extract_entries: Extract the entries of a dataframe that match specific rules

Description Usage Arguments Examples

View source: R/extract_entries.R

Description

Read a dataframe and extract from the specified column and entrie that match a set of rules specified in the rules_list argument. See example for more details. Keep the column names of the 2nd level list of the rules_list as they are in the example.

Usage

1
extract_entries(x, lookup_col, rules_list, return_summary = FALSE)

Arguments

x

A dataframe containing all the values to be examined.

lookup_col

Column name of the column with the identifiers. Match the name exactly.

rules_list

A list of lists containing the rules for the selection of identifiers. See example for more details. Every element of the rules_lest is a list with four elements. Keep the names of each of these element as it is in the example. In info describe the comparison. This is just for you to remember what you are comparing, so just write a text. The column element is used to match the column of the dataframe x that will be used for the evaluation. The rule can take values ">=", ">", "=", "<", "<=", "in", "not in". The value element of the list is the value that will be compared. It can be a single element vector or a vector with multiple elements. Depending on the comparison it can be numeric or character vector. See example.

return_summary

Default value is FALSE. If set to TRUE the output will be a dataframe with the number of elements that match the comparison.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
rules <- list(comp1 = list(info = "Is greter than 3",
                           column = "y",
                           rule = ">=",
                           value = "3"),
              comp2 = list(info = "Is equal to e",
                           column = "z",
                           rule = "=",
                           value = "e"),
              comp3 = list(info = "Is either b, d or f",
                           column = "z",
                           rule = "in",
                           value = c("b", "d", "f")),
              comp4 = list(info = "Is not c or d",
                           column = "z",
                           rule = "not in",
                           value = c("c", "d")))

x <- LETTERS[seq(1:6)]
y <- seq(1:6)
z <- letters[seq(1:6)]
d <- data.frame(x = x, y = y, z = z)

matched_ids_list <- extract_entries(x = d,
                                    lookup_col = "x",
                                    rules_list = rules)

tkostas/komics documentation built on May 24, 2019, 7:31 a.m.