Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write equation including `abs` inside, using Rmarkdown?

Tags:

math

r

r-markdown

I have managed to write the whole equation Equation I want to write

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:

Rmarkdown output

Could anyone help figure out how to get abs right here? Thanks

like image 297
Daniel Avatar asked May 24 '16 11:05

Daniel


2 Answers

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)$$

Image of Output

edit: When I originally posted this answer, I couldn't embed images yet. Now replaced link with embed.

like image 61
hdkrgr Avatar answered Oct 08 '22 22:10

hdkrgr


Using mathjax, you can use the "pipe" symbol |to indicate absolute values.

Try this:

$$ |-3| $$

enter image description here

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:

enter image description here

like image 41
Andrie Avatar answered Oct 09 '22 00:10

Andrie