rokro
May 17, 2018, 9:06am
1
I want to have some conditional words in my R Markdown document. Depending of the outcome in some of the calculations from the tables different words should show up in the ordinary text. Please, see my example below:
The table (a chunk):
testtabell <- matrix(c(32, 33, 45, 67, 21, 56, 76, 33, 22), ncol=3,byrow = TRUE)
colnames(testtabell) <- c("1990", "1991", "1992")
rownames(testtabell) <- c("Region1", "Region2", "Region3")
testtabell <- as.table(testtabell)
testtabell
This should be in the inline code and generate different word options in the regular text flow in the RMD:
r if testtabell[2,2]-[2,1] < testtabell[3,2]-testtabell[3,1] then type "under" or else "above"
Did you miss "testtabell" before "[2,1]" here?
rokro:
r if testtabell[2,2]-[2,1] < testtabell[3,2]-testtabell[3,1] then type "under" or else "above"
In that case, use the ifelse
function, as follows.
---
title: "try"
output: pdf_document
---
some text
```{r}
testtabell <- matrix(c(32, 33, 45, 67, 21, 56, 76, 33, 22), ncol=3,byrow = TRUE)
colnames(testtabell) <- c("1990", "1991", "1992")
rownames(testtabell) <- c("Region1", "Region2", "Region3")
testtabell <- as.table(testtabell)
testtabell
```
some text
some text `r ifelse(testtabell[2, 2] - testtabell[2, 1] < testtabell[3, 2] - testtabell[3, 1], "under", "above")` some test
some text
This generates try.pdf (96.4 KB), and most probably that's what you are looking for.
1 Like
rokro
May 17, 2018, 3:40pm
3
Thanksgiving you so much!
If your problem is solved, will you please mark the question solved by choosing the solution ?
1 Like
system
Closed
May 18, 2019, 4:10pm
5
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.