Skip to content
Back to formatted view

Raw Message

Message-ID: <CABcx46D_isFkbjCB_uN-epssdoOsnyx34uu7ey-aQHkkWOkk2Q@mail.gmail.com>
Date: 2016-04-26T22:35:04Z
From: John
Subject: How to print the frequency table (produced by the command "table" to Excel

Hi,

   How could we print the frequency table (produced by "table") to an Excel
file?
   Is there an easy way to do so? Thanks,

Miao

> df <- data.frame(x = 1:3, y = 3:1, z = letters[1:3])

> table(df[,c("y","z")])
   z
y   a b c
  1 0 0 1
  2 0 1 0
  3 1 0 0
> test<-table(df[,c("y","z")])
> as.data.frame(test)
  y z Freq
1 1 a    0
2 2 a    0
3 3 a    1
4 1 b    0
5 2 b    1
6 3 b    0
7 1 c    1
8 2 c    0
9 3 c    0
> as.matrix(test)
   z
y   a b c
  1 0 0 1
  2 0 1 0
  3 1 0 0
> testm<-as.matrix(test)
> testm
   z
y   a b c
  1 0 0 1
  2 0 1 0
  3 1 0 0
> typeof(testm)
[1] "integer"

	[[alternative HTML version deleted]]