R тетрадный стол форматирование - PullRequest
0 голосов
/ 21 сентября 2018

Я использую ноутбук R и хочу составить таблицу.

r notebook screen или как это:

Но когда я "Предварительный просмотр", я получаю это

|gender           | male                          | female                        |
| diabetes--------| Y-------------| N-------------| Y-------------| N-------------| 
| age group       | 0 | 1 | 2 | 3 | 0 | 1 | 2 | 3 | 0 | 1 | 2 | 3 | 0 | 1 | 2 | 3 |
|                 |               |               |               |               |
| None            | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 |
| R               | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 |
| I1              | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 |
| R-I1            | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 |
| I1-R            | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 |
| I1-I2           | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 |
| R-I1-I2         | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 |
| I1-R-I2         | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 |
| I1-I2-R         | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 | p0| p1| p2|p3 |

or like this.

не могли бы выпомогите мне составить таблицу, которую я хотел бы сгенерировать?

Заранее спасибо!

1 Ответ

0 голосов
/ 24 сентября 2018

Вы можете попробовать kable пакет

library(tidyverse)
library(kableExtra)

df <- data.frame(
    matrix(c(
     "None","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
     "R","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
     "I1","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
     "R-I1","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
     "I1-R","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
     "I1-I2","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
     "R-I1-I2","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
     "I1-R-I2","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
     "I1-I2-R","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3"), 
    nrow = 9, byrow = TRUE), 
  stringsAsFactors = FALSE)

kable(df, col.names = rep("", ncol(df))) %>% 
  kable_styling() %>%
  add_header_above(c("age group" = 1,"0" = 1,"1" = 1,"2" = 1,"3" = 1,"0" = 1,"1" = 1,"2" = 1,"3" = 1,
                 "0" = 1,"1" = 1,"2" = 1,"3" = 1,"0" = 1,"1" = 1,"2" = 1,"3" = 1)) %>%
  add_header_above(c("diabetes" = 1, "Y" = 4, "N" = 4, "Y" = 4, "N" = 4)) %>%
  add_header_above(c("gender" = 1, "male" = 8, "female" = 8))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...