AllObs: Display all observations in a table.

View source: R/AllObs.R

AllObsR Documentation

Display all observations in a table.

Description

These functions generate the code for a tabular table to include all observations in a dataset, possibly divided up according to other factors.

Usage

AllObs(data = NULL, show = FALSE, label = "Obsn.", within = NULL)
RowNum(within = NULL, perrow = 5, show = FALSE, label = "Row", data = NULL)

Arguments

data

The full dataset, used only to find the number of observations.

show

Whether to show the observation number or row number in the table.

label

The label to use when show = TRUE.

within

A factor or list of factors by which to break up the observations.

perrow

How many observations per row when RowNum is used in the row specification, or per column when it is part of the column specification.

Details

AllObs is used to display all of the observations in a dataset. It generates a (usually undisplayed) factor with a different level for each observation, sets a function to display the value, and calls DropEmpty to suppress display of empty rows, columns or cells.

If the within argument is specified in AllObs, the factor levels are restarted within each grouping. (within is interpreted as the INDEX argument of tapply, with one exception described below.) This may be useful when displaying the observation number, and is definitely useful if AllObs is used as a column specification in the table. It will also save some computation time if the table is very large, since fewer factor levels will be generated and later dropped.

RowNum is unlikely to be useful in a table by itself, but is helpful when displaying large datasets with AllObs. It allows a large number of observations to be broken into several rows and columns.

Because RowNum affects both rows and columns, its use is somewhat unusual. Normally it should be called before calling tabular, and its result saved in a variable. That variable (e.g. rownum) is used in the row specification for the table wrapped in I(), and in the column specification of the table in the within argument to AllObs. (This is the exception mentioned above.)

Despite its name, RowNum can be used as a column specifier, if you'd prefer column-major ordering of the values displayed in the table.

Value

Both AllObs and RowNum return language objects to be used on tabular formulas.

See Also

tabular, DropEmpty

Examples

tabular(Factor(cyl)*Factor(gear)*AllObs(mtcars) ~ 
               rownames(mtcars) + mpg, data=mtcars)
    
rownum <- with(mtcars, RowNum(list(cyl, gear)))
tabular(Factor(cyl)*Factor(gear)*I(rownum) ~
        mpg * AllObs(mtcars, within = list(cyl, gear, rownum)), 
        data=mtcars)

tables documentation built on Oct. 17, 2022, 3:01 p.m.