[R] exporting ftable

Leandro Marino
Wed, 02 Jul 2008 19:56:52 -0000

How can I export an ftable object in the same format that appears in R
command window?
For testing that i was using this example that is in help of this function.


## Start with a contingency table.
ftable(Titanic, row.vars = 1:3)
ftable(Titanic, row.vars = 1:2, col.vars = "Survived")
ftable(Titanic, row.vars = 2:1, col.vars = "Survived")

## Start with a data frame.
x <- ftable(mtcars[c("cyl", "vs", "am",
"gear")])
x
ftable(x, row.vars = c(2, 4))

## Start with expressions, use table()'s "dnn" to change labels
ftable(mtcars$cyl, mtcars$vs, mtcars$am, mtcars$gear, row.vars = c(2, 4),
       dnn = c("Cylinders", "V/S", "Transmission",
"Gears"))


When I tried to export the object x i have thsis result:
"V1" "V2" "V3"
"1" 0 0 0
"2" 0 0 1
"3" 1 2 0
"4" 0 6 1
"5" 0 0 0
"6" 0 2 1
"7" 2 2 0
"8" 0 0 0
"9" 12 0 0
"10" 0 0 2
"11" 0 0 0
"12" 0 0 0

I used to export:  write.table(x,"c:/x.txt")

Thanks in advance!

Best regards,




Atenciosamente,
Leandro Lins Marino
Centro de Avalia??o
Funda??o CESGRANRIO
Rua Santa Alexandrina, 1011 - 2? andar
Rio de Janeiro, RJ - CEP: 20261-903
( (21) 2103-9600 R.:236
( (21) 8777-7907
* leandro em cesgranrio.org.br
"Aquele que suporta o peso da sociedade
    ? precisamente aquele que obt?m
 as menores vantagens". (SMITH, Adam)

P  Antes de imprimir pense em sua responsabilidade e compromisso com o MEIO
AMBIENTE