0

I'd like to pipe gt at the end of this command but the function creates a list, which is not allowed in gt()

Error in UseMethod("group_vars"): no applicable method for 'group_vars' applied to an object of class "c('matrix', 'array', 'list')"`

test <- datasets::attenu%>% map(function(x) (sum(is.na(x)))) 
test %<>% t(.) 

I can do it if

datasets::attenu %>% map(function(x) (sum(is.na(x)))) %>% as_tibble() %>% gt::gt()

but then I can't transpose the table

test <- t(test)

at any point. Any suggestions about how to make the table vertical? Maybe the axis-flip is a "bug" that can be added to an update.

smci
  • 32,567
  • 20
  • 113
  • 146
ibm
  • 744
  • 7
  • 14

1 Answers1

1

You can first summarise and get data in long format :

library(dplyr)
library(tidyr)

datasets::attenu %>%
   summarise(across(.fns = ~sum(is.na(.)))) %>%
   #Or use summarise_all in older version of dplyr
   #summarise_all(~sum(is.na(.))) %>%
   pivot_longer(cols = everything()) %>%
   gt::gt()

enter image description here

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213