Petite suggestion, j'ai l'impression que votre second "problème" n'est pas vraiment lié au premier.
Si c'est bien le cas, peut-être serait-il mieux (plus clair) de faire un nouveau "post" décrivant un peu plus le contexte.
Parce-que le code que vous proposer ne peut pas être optimisé.
Vous vouliez une matrice, vous avez une matrice dont les dimensions et les noms sont imposés par vous dans le code fournit.
Notamment, le "all_table" qui est strictement identique aux autres tableaux.
Au passage, le package/fonction "reprex::reprex" est un bon allié pour créer un exemple reproductible (renvoie une sortie en markdown).
Par exemple:
Code : Tout sélectionner
reprex::reprex({
hop_col_title <- c("patients_total", "patients_restants", "patients_exclus", "interventions_total", "interventions_restantes", "interventions_exclues") #titre colonnes
hop_row_title <- c("3", "6", "9", "12") # titre lignes
CHD_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title)) #tableau de 4 lignes, 6 colonnes
CHV_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
CHa_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
CHDCHV_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
CHDCHa_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
CHVCHa_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
all_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
all_table
})
Renvoie
Code : Tout sélectionner
``` r
hop_col_title <- c("patients_total", "patients_restants", "patients_exclus", "interventions_total", "interventions_restantes", "interventions_exclues") #titre colonnes
hop_row_title <- c("3", "6", "9", "12") # titre lignes
CHD_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title)) #tableau de 4 lignes, 6 colonnes
CHV_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
CHa_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
CHDCHV_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
CHDCHa_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
CHVCHa_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
all_table <- matrix(nrow = 4, ncol = 6, dimnames = list(hop_row_title, hop_col_title))
all_table
#> patients_total patients_restants patients_exclus interventions_total
#> 3 NA NA NA NA
#> 6 NA NA NA NA
#> 9 NA NA NA NA
#> 12 NA NA NA NA
#> interventions_restantes interventions_exclues
#> 3 NA NA
#> 6 NA NA
#> 9 NA NA
#> 12 NA NA
```
<sup>Created on 2019-02-27 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)</sup>
Cordialement,