Search code examples
rhideformattable

R - formattable - trying to hide column 0


I am displaying a dataframe using formattable

formattable (cohens_d_effects, digits = 2)

My table looks like this:

enter image description here

I am able to hide columns using the list argument when I got a column name:

formattable (cohens_d_effects, list (d_names = FALSE), digits = 2)

But how to hide these "id-numbers" on the left (column 0)?


Reproducible example from comment below:

d_names = 1:10 
d = 11:20 
Winners = 15:24 
a <- data.frame(d_names, d, Winners) 
a <- a[order(-d), ] 
b <- subset(a, d > 14) 
formattable(b, digits = 2)

Solution

  • As Rui Barradas commented, those are row names. A simple solution is to set them to NULL,

    # Load library
    library(formattable)
    
    # Example from above
    d_names = 1:10 
    d = 11:20 
    Winners = 15:24 
    a <- data.frame(d_names, d, Winners) 
    a <- a[order(-d),] 
    b <- subset(a, d > 14) 
    
    # Set to NULL before creating the table
    row.names(b) <- NULL
    
    # Create the table
    formattable(b, digits = 2)
    

    giving,

    enter image description here