Different R Markdown in same document for each output type
I was able to get different inclusions and rendering with the following document:

---
output: html_document
---

```{r, results='asis', echo=FALSE}
library(knitr)
pandocto &lt;- opts_knit$get("rmarkdown.pandoc.to")
if (pandocto == "docx") {
  cat("## Word Heading\n\nHello world")
} else if (pandocto == "html") {
  cat("## HTML Heading\n\nHello world-wide-web")
} else if (pandocto == "latex") {
  cat("## LaTeX/PDF Heading\n\nHeLlO wOrLd")
}
```

```{r}
str(opts_knit$get()
```


If you vary the head YAML with what you need, perhaps one of:

output: html_document
output: pdf_document
output: word_document


you can see the difference. The tricks are knowing that rmarkdown tells you the format to which pandoc is rendering, and the use of results='asis' in the block header to capture the output as raw-markdown (or latex, as appropriate).

I included the second block (str(...)) so you can see what else is "known" during document compilation/rendering.