Reputation: 610
I am using the tabular()
function to produce tables in r (tables
library).
I want to compute CI's from the data in the output (let mytable
be the output from tabular()
). Simple enough I thought, except when I go to call a value from the matrix, I get the error Error in mytable[1, i] - 1 : non-numeric argument to binary operator
. I thought this was odd, as when I call up a particular cell of the matrix (where as.matrix
returned true for mytable
), for example mytable[1, i]
for some i, I get an interger. I then do the as.list
for mytable and get true also, so I am not sure what this means. I guess the tabular()
function stores the results as a special kind of matrix.
I am only trying to pull out the mean,sdev, and n, which I am able to just by typing the cell location, for example mytable[1, i]
would return an 86. However, when I try to call up the value in qt(.975,df=(mytable[1,i]-1))
for example, I get the error above. Not sure really how to approach this except to manually enter the values into another matrix (which I would like to avoid). Or, if I can compute CI's directly in the tabular()
function that would work also. Cheers.
Upvotes: 1
Views: 91
Reputation: 173667
I shall quote for you the Value section of the documentation on the function ?tabular
:
An object of S3 class "tabular". This is a matrix of mode list, whose entries are computed summary values, with the following attributes:
rowLabels - A matrix of labels for the rows. This will have the same number of rows as the main matrix, but may have multiple columns for different nested levels of labels. If a label covers multiple rows, it is entered in the first row, and NA is used to fill following rows.
colLabels - Like rowLabels, but labelling the columns.
table - The original table expression being displayed. A list of the original format specifications are attached as a "fmtlist" attribute.
formats - A matrix of the same shape as the main result, containing NA for default formatting, or an index into the format list.
As the documentation says, each element of the matrix is a list. If your tabular
object is called tab
type tab[1,1]
and you should see a list containing one of your table values. If I wanted to modify that value, I would probably do something like:
tab[1,1]$term <- value
just like you would modify values in any other list.
Type attributes(tab)
and you'll see the items listed above, containing a lot of the formatting information and row/col headers.
Upvotes: 1