0

I am trying to create a report including the output of a linear regression model (included in a list). However I can't get rid of annoying characters like [[1]] or #'s when knitting. Here is my code:


{r error=FALSE, warning=FALSE, message=FALSE}

x = c(1,2,3)
y = c(1,2,3)
df = data.frame(x,y)
lm.fit = lm(y ~ x , data = df)
mylist = list(lm.fit)
mylist[1]

And it gives me this:

enter image description here

I also tried include = FALSE but that removes the report. Does anyone know a better way for reporting such outputs in a nice professional way without those ugly #'s and [[1]]?

Amin Shn
  • 532
  • 2
  • 11
  • Possible duplicate of https://stackoverflow.com/questions/15081212/remove-hashes-in-r-output-from-r-markdown-and-knitr - can you check if this solves it for you? – thelatemail Jan 24 '21 at 23:47
  • @thelatemail That solution doesn't remove [[1]]. I am still struggling with removing that. – Amin Shn Jan 24 '21 at 23:48
  • 1
    Use `mylist[[1]]` instead of `mylist[1]` to return the list item, rather than the whole list. Or don't wrap `lm.fit` in `list()` at all. That issue isn't to do with Markdown however. – thelatemail Jan 24 '21 at 23:52
  • 1
    @thelatemail This is just a minimal example code. I have to use list() in my original code. Thanks, using mylist[[1]] solved the problem. – Amin Shn Jan 24 '21 at 23:57
  • Glad it helped. For future searchers, https://stackoverflow.com/questions/1169456/the-difference-between-bracket-and-double-bracket-for-accessing-the-el would be the canonical question discussing the single vs double bracket issues. – thelatemail Jan 25 '21 at 01:08

0 Answers0