sbac
March 10, 2021, 8:03pm
1
I want to use the results of a k-s test with an inline code using RMarkdown. I can get `ks$statistic[[1]]`

and `ks$p.value[[1]]`

but when I use them inline, I get an error.

```
---
title: "ks test2"
output:
word_document: default
---
```{r setup, include=FALSE}
library(knitr)
knitr::opts_chunk$set(echo = TRUE, results="asis")
```

```
x <- rnorm(50)
ks <- ks.test(x, "pnorm", mean=mean(x),
sd=sd(x))
df <- length(x)
```

Based on K-S test (`r D (df) = ks$statistic[[1]], p = ks$p.value[[1]]`

), we can conlude something.

The two expressions need to be inlined separately. They work

```
x <- rnorm(50)
ks <- ks.test(x, "pnorm", mean=mean(x),
sd=sd(x))
df <- length(x)
ks$statistic[[1]]
#> [1] 0.07133526
ks$p.value[[1]]
#> [1] 0.9451946
```

but just not when used with the surrounding non-statements

```
> (r D (df) = ks$statistic[[1]], p = ks$p.value[[1]])
Error: unexpected symbol in "(r D"
```

Based on K-S test D (df) = !r ks$statistic[[1]]!, p = !r ks$p.value[[1]]!, we can conclude something.

with backticks in place of `!`

.

1 Like

system
Closed
March 17, 2021, 8:31pm
3
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.