Skip to content

Commit

Permalink
#71: split the summary table
Browse files Browse the repository at this point in the history
  • Loading branch information
kaz462 committed Aug 2, 2023
1 parent b129ca3 commit 448d198
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions posts/2023-07-24_rounding/rounding.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,35 @@ However, they use different approaches when rounding off a 5:

Although base R does not have the option for "round half up", there are functions available in other R packages (e.g., `janitor`, `tidytlg`).

The following table lists some often-used rounding methods and their corresponding functions in SAS and R.

+---------------+----------------------------------------+----------------------------+-------------------+-----------------+--------------------+
| | round half up | round to even | round up | round down | round towards zero |
+:=============:+:======================================:+:==========================:+:=================:+:===============:+:==================:+
| SAS | `round()` | `rounde()` | `ceil()` | `floor()` | `int()` |
+---------------+----------------------------------------+----------------------------+-------------------+-----------------+--------------------+
| R | ::: {style="background-color: yellow"} | <div> | <div> | <div> | <div> |
| | `janitor::round_half_up()` | | | | |
| | | `base::round()` | `base::ceiling()` | `base::floor()` | `base::trunc()` |
| | <div> | | | | |
| | | </div> | </div> | </div> | </div> |
| | `tidytlg::roundSAS()` | | | | |
| | | | | | |
| | </div> | | | | |
| | ::: | | | | |
+---------------+----------------------------------------+----------------------------+-------------------+-----------------+--------------------+
| Example: 1.45 | 1.5 | 1.4 | 2 | 1 | 1 |
| | | | | | |
| | (round to 1 decimal place) | (round to 1 decimal place) | | | |
+---------------+----------------------------------------+----------------------------+-------------------+-----------------+--------------------+

In general, there are many often used rounding methods. In the table below, you can find examples of them applied to the number 1.45.

+---------------+----------------------------+----------------------------+----------+------------+--------------------+
| | round half up | round to even | round up | round down | round towards zero |
+:=============:+:==========================:+:==========================:+:========:+:==========:+:==================:+
| Example: 1.45 | 1.5 | 1.4 | 2 | 1 | 1 |
| | | | | | |
| | (round to 1 decimal place) | (round to 1 decimal place) | | | |
+---------------+----------------------------+----------------------------+----------+------------+--------------------+

Here are the corresponding ways to implement these methods in SAS and R.

+---------+----------------------------------------+-----------------+-------------------+-----------------+--------------------+
| | round half up | round to even | round up | round down | round towards zero |
+:=======:+:======================================:+:===============:+:=================:+:===============:+:==================:+
| SAS | `round()` | `rounde()` | `ceil()` | `floor()` | `int()` |
+---------+----------------------------------------+-----------------+-------------------+-----------------+--------------------+
| R | ::: {style="background-color: yellow"} | <div> | <div> | <div> | <div> |
| | `janitor::round_half_up()` | | | | |
| | | `base::round()` | `base::ceiling()` | `base::floor()` | `base::trunc()` |
| | <div> | | | | |
| | | </div> | </div> | </div> | </div> |
| | `tidytlg::roundSAS()` | | | | |
| | | | | | |
| | </div> | | | | |
| | ::: | | | | |
+---------+----------------------------------------+-----------------+-------------------+-----------------+--------------------+


This table is summarized from links below, where more detailed discussions can be found -

Expand Down

0 comments on commit 448d198

Please sign in to comment.