[R] Entering a table

Thomas
Tue, 21 Aug 2012 12:48:52 -0000

I'm trying to enter a frequency table manually so that I can run a
goodness of fit test (I only have the frequencies, I don't have the
raw data).

So for example, let's say I want to re-create the HorseKicks table:

library(vcd)

data(HorseKicks)
str(HorseKicks)

  'table' int [1:5(1d)] 109 65 22 3 1
  - attr(*, "dimnames")=List of 1
   ..$ nDeaths: chr [1:5] "0" "1" "2"
"3" ...

I tried this the following but it didn't work:

vex <- matrix(c(0,109,1,65,2,22,3,3,4,1), nrow=2, ncol=5)
vec <- as.table(vex)
str(vec)

  table [1:2, 1:5] 0 109 1 65 2 22 3 3 4 1
  - attr(*, "dimnames")=List of 2
   ..$ : chr [1:2] "A" "B"
   ..$ : chr [1:5] "A" "B" "C" "D" ...

I also tried:

vex <- c(109,65,22,3,1)
vec <- as.table(vex)
str(vec)

  table [1:5(1d)] 109 65 22 3 1
  - attr(*, "dimnames")=List of 1
   ..$ : chr [1:5] "A" "B" "C" "D" ...

goodfit(HorseKicks) works fine
goodfit(vec) does not

Thank you,

Thomas

This message and any attachment are intended solely for the addressee and may
contain confidential information. If you have received this message in error,
please send it back to me, and immediately delete it.   Please do not use, copy
or disclose the information contained in this message or in any attachment.  Any
views or opinions expressed by the author of this email do not necessarily
reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.