Creation of dataframe

thanks to table() : table<-with(commun,table(QUINTILE,resul_colo_final))

I have this table :

        resul_final
QUINTILE          1                      2       3      4
       1          1                      0       4     11
       2          0                      0       8     15
       3          0                      1       7     11
       4          0                      1       8     13
       5          0                      2       7     23

and thanks to the gt package I want to display a data frame. But to do it I have to convert my table in a data frame and if I did it, like this :

table<-as.data.frame(with(commun,table(QUINTILE,resul_final)))

It gave me this result :

QUINTILE resul_final Freq
1 0 1
2 0 0
3 0 0
4 0 0
5 0 0
1 1 0
2 1 0
3 1 1
4 1 1
5 1 2
1 2 4
2 2 8
3 2 7
4 2 8
5 2 7
1 3 11
2 3 15
3 3 11
4 3 13
5 3 23

my gt code :

table %>%
  gt() %>%
  tab_header(
    title = md("**Frequences de classes**"))

How can I do to have the same dataframe in gt than in table()?

library(gt)
library(dplyr) # for slice

(t1 <- table(iris$Species))
#problem orientation
gt(data.frame(t1))

#corrected 
(t1x <- t(data.frame(t1)))
(top <- t1x[1,])

d1 <- data.frame(t1x)
names(d1) <- top
gt(dplyr::slice(d1,-1))

I'm sorry but in my case, it doesn't work. And I don't really have a problem of orientation, more a problem of group by or something like this

Please make a reprex and i will look at your case

I'm sorry but I don't know how to do a reprex from my first table in my question. I think this is the reprex you wait for?

Im guessing you didnt type this out, that it came from your R session. Only not in reprex suitable fahsion.
Therefore if you have it then reprex it in the normal way.
Im sure i'e shared the reprex guide with you multiple times in the past.

Here it is again.

First I don't understand why when I convert my object table in a df it transpose my "line" resul_final into a column, why put it in dataframe don't conserve my things?

I know how to do a reprex but not on this kind of table

Have you used dput() ?

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.