extra unit tests, add row.names to freq

This commit is contained in:
dr. M.S. (Matthijs) Berends committed 2018-06-19 15:20:14 +02:00
1 parent bdc860e29c
commit 4a027f3c34
8 files changed
+77 -25

No files matched your search

Executable → Regular
+8 -3
View 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) %>%
+13 -3
View File
@@ -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: