How to write equation including `abs` inside, using Rmarkdown?
10,582
Solution 1
Expanding on Andrie's answer:
Another way to write absolute value is
\lvert -3 \rvert
To automatically adjust the size of the vertical lines to what's inside them, use
\left\lvert -3 \right\rvert
In your case, this becomes:
$$MAPE = \frac{1}{n} \sum_{d_i} (\frac{1}{q} \sum_{t_j}\left\lvert{\frac{gap_{i,j}-s_{i,j}}{gap_{i,j}}}\right\rvert)$$
edit: When I originally posted this answer, I couldn't embed images yet. Now replaced link with embed.
Solution 2
Using mathjax, you can use the "pipe" symbol |
to indicate absolute values.
Try this:
$$ |-3| $$
In your case:
$$MAPE = \frac{1}{n} \sum_{d_i} (\frac{1}{q} \sum_{t_j} |\frac{gap_{i,j}-s_{i,j}}{gap_{i,j}}| )$$
This gives:
Author by
Daniel
Updated on June 13, 2022Comments
-
Daniel almost 2 years
I have managed to write the whole equation
using the following code in Rmarkdown
$$MAPE = \frac{1}{n} \sum_{d_i} (\frac{1}{q} \sum_{t_j} \abs{\frac{gap_{i,j}-s_{i,j}}{gap_{i,j}}} )$$
However, in Rmarkdown, the code above returns:
Could anyone help figure out how to get
abs
right here? Thanks -
Bob__ almost 8 yearsI'd use
\left(
and\right)
too, instead of( ... )
. -
hdkrgr almost 8 yearsThanks for the addition. Yes, that's how I would do it, too. I just wanted to reduce the changes in the original code to a minimum here.
-
Daniel almost 8 yearsThanks for this straightforward solution!
-
Daniel almost 8 yearsThis solution has more to write but prettier. Thanks