Search code examples
rgridgridextra

How to put the inequality symbol (<=) in the rows of a table with grid.table in R


I can't get the attached table, (<=) to show up as enter image description here

enter image description here

The table is variable and has been constructed as follows:

limites1 <- function (m ){
  h1 <- NULL
  for (i2 in 1: m){
    h1 <-c(h1 , paste0(unique(sort(v))[i2],  c( paste0( "<=  x  < " )) ,unique(sort(v))[i2+1] ))
  }
  h1
}

a <- unique(sort(v))[1]
b <- unique(sort(v))[n18]
prueba <- c(0, cumsum(as.numeric(prop.table(table(v)))) )
intervalos1 <- c( paste0("x<",a) ,limites1((1/(mean(unique(sort(v)))/sum(unique(sort(v)))))-1), paste0("x>=",b))


tablasolucion <-data.frame (intervalos1 , prueba)
colnames (tablasolucion) <-c(  "x" ,  'F==P(X<=x)' )
tt <- ttheme_default(core = list(fg_params = list(parse=TRUE)),colhead=list(fg_params = list(parse=TRUE)))
grid.newpage()
grid.table(tablasolucion, rows = NULL, theme=tt)

enter image description here


Solution

  • I don't think plotmath can parse "1<=2<3", but you can use invisible grouping by enclosing the part of expression in {}, so that it tries to parse "{1<=2}<3"

    This should work:

    h1 <-c(h1 , paste0("{", unique(sort(v))[i2],  c( paste0( "<=x}<" )) ,unique(sort(v))[i2+1] ))