0

I would like to put a table in a file word with the package RTF.

My code is

univ_quali<-function(dataset){ print(cbind(prop.table(table(sex)), t(t(table(sex)))))}


univ_quali(sex)

 [,1] [,2]
1 0.5754717   61
2 0.4245283   45

I tried this

 addTable(rapportrtf,univ_quali(sex))

but it return a table like that on the word document:

V1                  V2
0.5754717          61
0.4245283          45

I would like

     percentage         sum
  1   0.5754717          61
  2   0.4245283          45

Reproductible exemple:

set.seed(24)
sex <- sample(c("male", "female"), 106, replace=TRUE)

How can i do?

E.bl
  • 27
  • 4
  • You can try `ReporteRs` : http://stackoverflow.com/questions/25425993/data-frame-to-word-table/25427314#25427314 – Victorp Apr 17 '16 at 10:29
  • Thank you for your answer but i really need to only use package rtf. – E.bl Apr 17 '16 at 10:33
  • why is `dataset` a parameter in `univ_quali` if you aren't using it? – hrbrmstr Apr 17 '16 at 11:18
  • it's not true because i tried also to search. My course doesn't explain enough. And i finally find this one by myself! – E.bl Apr 17 '16 at 12:42

1 Answers1

0

I finally find the answer!

tab_sex<-univ_quali(sex)
rownames(tab_sex)<-c("1","2")
colnames(tab_sex)<-c("Pourcentage","Somme")
addTable(rapportrtf,cbind(rownames(tab_sex),tab_sex))
E.bl
  • 27
  • 4