look_up: Look Up Values in a Data Frame

Description Usage Arguments Details Value Examples

View source: R/look_up.R

Description

A convenience function to easily look for values in a data frame.

Usage

1
look_up(data, ..., bin = FALSE, value = "value")

Arguments

data

A reference data frame.

...

Individual characteristics, should be named like the columns of data.

bin

Either logical: should all numeric variable be binned, or character vector giving the names of variables to bin (see examples).

value

The value to extract ffrom the reference data frame.

Details

This function is mostly used to extract population informations (such as mortality rates), given some individual caracteristics.

If binning is activated, numeric individual characteristics are matched to the corresponding reference value that is directly inferior.

Value

A vector of values, same lenght as ....

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
40
41
tempdf <- expand.grid(arg1 = c("A", "B", "C"), arg2 = 1:4, arg3 = 1:5)
tempdf$value <- 1:60

look_up(
  data = tempdf,
  value = "value",
  arg1 = c("A", "B", "C", "B", "A"),
  arg2 = c(1, 1, 3.2, 3.0, 5), 
  arg3 = c(-1, 1, 1, 2, 3)
)

# binning doesnt catch values lesser than the smaller
# reference value
look_up(
  data = tempdf,
  value = "value",
  arg1 = c("A", "B", "C", "B", "A"),
  arg2 = c(1, 1, 3.2, 3.0, 5), 
  arg3 = c(-1, 1, 1, 2, 3),
  bin = TRUE
)
# bin can alos be given as a charater vector
# to avoid binning all numeric variables
look_up(
  data = tempdf,
  value = "value",
  arg1 = c("A", "B", "C", "B", "A"),
  arg2 = c(1, 1, 3.2, 3.0, 5), 
  arg3 = c(-1, 1, 1, 2, 3),
  bin = c("arg2")
)

age_related_df <- data.frame(age = 10 * 0:9, decade = 1:10)

look_up(age_related_df, age = c(0, 10, 20), value = "decade")

# binning might help in the situation
look_up(age_related_df, age = c(5, 15, 23.5), 
        value = "decade")
look_up(age_related_df, age = c(5, 15, 23.5), 
        value = "decade", bin = TRUE)

pierucci/heemod documentation built on July 15, 2018, 12:44 p.m.