kableExtra: remove decimal places for N (number of observation)

test

How do I remove decimal points from N? In other words, I want to keep Mean and Median with 2 decimal places, but present N as integer.

library(dplyr)
library(kableExtra)
# Example Data
df <- data.frame(
  stat = rep(c("Mean", "Median", "N"), times = 2),
  Y2008 = c(1.122, 1.42, 100, 2.122, 2.42, 200),
  Y2009 = c(1.152, 1.92, 250, 2.189, 2.49, 300)
)
# Table with kableExtra
df %>%
  rename (` ` = stat) %>% 
  kable(booktabs = TRUE, digits = 2) %>% pack_rows(
    index = c("Group 1" = 3, "Group 2" = 3)
  )

I think you'll need to convert your numbers to strings and then edit them accordingly.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.