1

I wish to display greek letter alpha in the table generated by the following code in R Markdown. How can I do it? Thanks!

rows = 1:100

cols = c(0.4, 0.2, 0.1, 0.05, 0.025, 0.01, 0.005, 0.001)

Q = NULL

for (a in rows){

  for (b in cols){

    q = qt(1-b, a)

    Q = append(Q,q)

  }

}

DF = data.frame(matrix(round(Q,3), ncol=8, byrow=TRUE))
DF= rbind(as.character(cols), DF)
DF = cbind(c("df/alpha",as.character(rows)), DF)

DF = unname(DF)
kable(DF)
Sam Chang
  • 61
  • 1
  • 5
  • A similar question was asked [here](https://stackoverflow.com/q/48873875/2799941), but there's not an official answer. The issue was resolved in the comments, but the correct syntax is actually in OP's question. Not sure if that means this is a duplicate - I'd lean towards keeping this current question open. – andrew_reece Feb 13 '20 at 06:03
  • Also, welcome to Stack Overflow @SamChang! – andrew_reece Feb 13 '20 at 06:04

1 Answers1

1

Use $ notation in strings to insert LaTeX symbols, including Greek letters. Like this:

DF = cbind(c("$\\alpha$",as.character(rows)), DF)

If you knit kable(DF), you'll see alpha appear in the first column header. Note that the symbol will not appear in the R console - you have to knit to see it.

andrew_reece
  • 20,390
  • 3
  • 33
  • 58