From e79fd84b942dd68502d9352f48413b6171cbe1ec Mon Sep 17 00:00:00 2001 From: ergz Date: Sat, 3 Sep 2022 01:08:26 -0700 Subject: [PATCH] intial --- .here | 0 .lintr | 6 ++++++ R/ch2.R | 27 +++++++++++++++++++++++++++ README.md | 1 + 4 files changed, 34 insertions(+) create mode 100644 .here create mode 100644 .lintr create mode 100644 R/ch2.R create mode 100644 README.md diff --git a/.here b/.here new file mode 100644 index 0000000..e69de29 diff --git a/.lintr b/.lintr new file mode 100644 index 0000000..c486a3c --- /dev/null +++ b/.lintr @@ -0,0 +1,6 @@ +linters: lintr::linters_with_defaults( + line_length_linter(120), + commented_code_linter = NULL, + trailing_whitespace_linter = NULL + ) + diff --git a/R/ch2.R b/R/ch2.R new file mode 100644 index 0000000..7694ce4 --- /dev/null +++ b/R/ch2.R @@ -0,0 +1,27 @@ +# install.packages("bayesrules") + +library(bayesrules) +library(dplyr) + +data(fake_news) +# make it a tibble for the sake printing +fake_news <- tibble::as_tibble(fake_news) + +fake_news |> glimpse() + +# proportion of each type of article +fake_news |> + group_by(type) |> + summarise( + n = n(), + prop = n / nrow(fake_news) # <- is there a NSE way + # of getting total rows of + # original DF? + ) + +# we can also do this with the tally function +fake_news|> + group_by(type) |> + tally() |> + mutate(prop = n / sum(n)) + diff --git a/README.md b/README.md new file mode 100644 index 0000000..6ec3dcb --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +A set of notes and examples from reading through the book _Bayes Rules!_. \ No newline at end of file