filter_eav: Filter an EAV tibble

Description Usage Arguments Examples

View source: R/filter.R

Description

Filter an EAV tibble

Usage

1
filter_eav(.data, ...)

Arguments

.data

a tbl_eav

...

filter conditions

.c

a single condition (to be replaced by dots...)

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
eav_tiny %>% group_by(empid) %>% filter_eav(lu("first") == "John")

eav_tiny %>% filter_eav(is.na(last))

# only gets explicit NA
tinyeav %>%
  filter(var == "last", is.na(value)) %>% {
  semi_join(tinyeav, ., by = "empid")
  }

# reversing the condition specially for NA
tinyeav %>%
  filter(var == "last", !is.na(value)) %>% {
  anti_join(tinyeav, ., by = "empid")}

# or first make missing data explicit
tinyeav %>%
  complete(nesting(empid), nesting(var)) %>%
  filter(var == "last", is.na(value)) %>% {
  semi_join(tinyeav, ., by = "empid")}

# or tidy first (this version makes it explicit)
tinyeav %>%
  spread(var, value) %>%
  filter(is.na(last)) %>%
  gather("var", "value", -empid) %>%
  arrange(empid)

# multiple conditions
tinyeav %>%
  filter_eav(first == "John" & last == "Smith")

tinyeav %>%
  group_by(empid) %>%
  summarize(include_row =
  						any(var == "first" & value == "John") &
  						any(var == "last" & value == "Smith")) %>%
  filter(include_row) %>% {
  semi_join(tinyeav, ., by = "empid")}

jameelalsalam/eavtools documentation built on Oct. 17, 2019, 1:45 a.m.