Beichen Lin
Beichen Lin

Reputation: 19

R markdown format, remove prefix

How can I remove the prefix like [1] when results are shown in R markdown?

e.g:

{r,comment=NA}
BRFSSdata=read.csv("/Users/chokiyoshizhen/Downloads/dso545/BRFSS.csv",header=T)
attach(BRFSSdata)
summary(height)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  48.00   64.00   67.00   67.18   70.00   93.00 
sd(height)
[1] 4.125954

Are there any ways to remove/suppress the [1], it's really frustrating.

Attached is csv file of sample raw data: height weight gender 70 175 f 75 189 m 77 193 m

Upvotes: 2

Views: 1223

Answers (1)

mrub
mrub

Reputation: 513

You can use the function writeLines() to print without the prefix:

a <- 3; writeLines(c("Hello world!", a))

This gives you:

Hello world!
3

If you want to print computations in continuous text in an R markdown file you can use inline code blocks:

```{r,comment=NA}
BRFSSdata=read.csv("/Users/chokiyoshizhen/Downloads/dso545/BRFSS.csv",header=T)
attach(BRFSSdata)
summary(height)
Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
48.00   64.00   67.00   67.18   70.00   93.00 
```

`r sd(height)`

Upvotes: 2

Related Questions