Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to write a quotient, with horizontal line, in a cell of a table in R

I want that in the quotient n_i/c_i, instead of the line being oblique, the line is horizontal. I try to use "\frac{}" but I get an error.
I attach image and code of the quotient with the oblique line.enter image description here

library(grid)
library(gridExtra)
library(glue)
data1P <- data.frame(c("[1, 5)", "[5, 7)", "[7, 9)", "[9, 10]"), 
            c("6", "7" ,"22" ,"23"),
            c("4", "2", "2", "1"),
            c("1.5", "3.5", "11" , "23"))

colnames(data1P) <- lapply(list("X\\Y= [1,4)","n[i]","c[i]","d[i]==paste(n[i]/c[i])"),glue)

tt <- ttheme_default(colhead=list(fg_params = list(parse=TRUE)))

grid.newpage()

grid.table(data1P, rows = NULL, theme=tt)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The language being used for the column names isn’t LaTeX, where "\frac{}" would work, it’s plotmath from R graphics, so the syntax is different. Your code works for me with this change:

colnames(data1P) <- lapply(list("X\\Y= [1,4)","n[i]","c[i]","d[i]==frac(n[i],c[i])"),glue)

i.e. use frac(n[i], c[i]) to get the fraction.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading