mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 15:21:58 +02:00
extra unit tests, add row.names to freq
This commit is contained in:
11
vignettes/freq.R
Executable file → Normal file
11
vignettes/freq.R
Executable file → Normal file
@ -7,13 +7,13 @@ library(dplyr)
|
||||
library(AMR)
|
||||
|
||||
## ---- echo = TRUE, results = 'hide'--------------------------------------
|
||||
# # just using base R
|
||||
# just using base R
|
||||
freq(septic_patients$sex)
|
||||
|
||||
# # using base R to select the variable and pass it on with a pipe
|
||||
# using base R to select the variable and pass it on with a pipe
|
||||
septic_patients$sex %>% freq()
|
||||
|
||||
# # do it all with pipes, using the `select` function of the dplyr package
|
||||
# do it all with pipes, using the `select` function of the dplyr package
|
||||
septic_patients %>%
|
||||
select(sex) %>%
|
||||
freq()
|
||||
@ -69,6 +69,11 @@ septic_patients %>%
|
||||
select(amox) %>%
|
||||
freq(na.rm = FALSE)
|
||||
|
||||
## ---- echo = TRUE--------------------------------------------------------
|
||||
septic_patients %>%
|
||||
select(hospital_id) %>%
|
||||
freq(row.names = FALSE)
|
||||
|
||||
## ---- echo = TRUE--------------------------------------------------------
|
||||
septic_patients %>%
|
||||
select(hospital_id) %>%
|
||||
|
@ -27,13 +27,13 @@ Frequency tables (or frequency distributions) are summaries of the distribution
|
||||
|
||||
To only show and quickly review the content of one variable, you can just select this variable in various ways. Let's say we want to get the frequencies of the `sex` variable of the `septic_patients` dataset:
|
||||
```{r, echo = TRUE, results = 'hide'}
|
||||
# # just using base R
|
||||
# just using base R
|
||||
freq(septic_patients$sex)
|
||||
|
||||
# # using base R to select the variable and pass it on with a pipe
|
||||
# using base R to select the variable and pass it on with a pipe
|
||||
septic_patients$sex %>% freq()
|
||||
|
||||
# # do it all with pipes, using the `select` function of the dplyr package
|
||||
# do it all with pipes, using the `select` function of the dplyr package
|
||||
septic_patients %>%
|
||||
select(sex) %>%
|
||||
freq()
|
||||
@ -143,12 +143,22 @@ septic_patients %>%
|
||||
|
||||
### Parameter `na.rm`
|
||||
With the `na.rm` parameter (defaults to `TRUE`, but they will always be shown into the header), you can include `NA` values in the frequency table:
|
||||
|
||||
```{r, echo = TRUE}
|
||||
septic_patients %>%
|
||||
select(amox) %>%
|
||||
freq(na.rm = FALSE)
|
||||
```
|
||||
|
||||
### Parameter `row.names`
|
||||
The default frequency tables shows row indices. To remove them, use `row.names = FALSE`:
|
||||
|
||||
```{r, echo = TRUE}
|
||||
septic_patients %>%
|
||||
select(hospital_id) %>%
|
||||
freq(row.names = FALSE)
|
||||
```
|
||||
|
||||
### Parameter `markdown`
|
||||
The `markdown` parameter can be used in reports created with R Markdown. This will always print all rows:
|
||||
|
||||
|
Reference in New Issue
Block a user