-
Notifications
You must be signed in to change notification settings - Fork 11
/
mutate.Rmd
60 lines (39 loc) · 1.52 KB
/
mutate.Rmd
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
title: "bupaR Docs | Mutate logs"
---
```{r echo = F, out.width="25%", fig.align = "right"}
knitr::include_graphics("images/icons/enrich.png")
```
***
# Mutate logs
```{r eval = F}
library(bupaverse)
library(dplyr)
```
```{r include = F}
library(bupaverse)
library(dplyr)
```
Next to [`augment()`](augment.html) for enriching an event log with calculated metrics, you can use `mutate()` to add more custom new variables to a log, or change the existing ones. The use of `mutate()` is especially convenient in combination with `group_by()`.
## Transforming variables
The code below transforms the _lacticacid_ variable, stored as a `character`, to a `numeric` variable.
```{r}
sepsis %>%
mutate(lacticacid = as.numeric(lacticacid)) -> sepsis
```
## Calculating variables
Below, we group the data by case using `group_by_case()`, and subsequently calculate the total _lacticacid_ value. Note that setting `na.rm = TRUE` is required as there are missing values present for this variable.
```{r}
sepsis %>%
group_by_case() %>%
mutate(total_lacticacid = sum(lacticacid, na.rm = TRUE)) %>%
ungroup_eventlog()
```
Before continuing to further analyses, not that you might want to ungroup the log using `ungroup_eventlog()`. More on [grouping](wrangling.html).
```
```{r footer, results = "asis", echo = F}
CURRENT_PAGE <- stringr::str_replace(knitr::current_input(), ".Rmd",".html")
res <- knitr::knit_expand("_button_footer.Rmd", quiet = TRUE)
res <- knitr::knit_child(text = unlist(res), quiet = TRUE)
cat(res, sep = '\n')
```