Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

table2matrix

Convert a table with counts to a matrix or data.frame representing those counts.


Description

Some historical sets are reported as summary tables of counts in a limited number of bins. Transforming these tables to data.frames representing the original values is useful for pedagogical purposes. (E.g., transforming the original Galton table of height x cubits in order to demonstrate regression.) The column and row names must be able to be converted to numeric values.

Usage

table2matrix(x, labs = NULL)
table2df(x, count=NULL,labs = NULL)

Arguments

x

A two dimensional table of counts with row and column names that can be converted to numeric values.

count

if present, then duplicate each row count times

labs

Labels for the rows and columns. These will be used for the names of the two columns of the resulting matrix

Details

The original Galton (1888) of heights by cubits (arm length) is in tabular form. To show this as a correlation or as a scatter plot, it is useful to convert the table to a matrix or data frame of two columns.

This function may also be used to convert an item response pattern table into a data table. e.g., the Bock data set bock.

Value

A matrix (or data.frame) of sum(x) rows and two columns.

Author(s)

William Revelle

See Also

cubits and bock data sets

Examples

data(cubits)
cubit <- table2matrix(psychTools::cubits,labs=c("height","cubit"))
describe(cubit)
ellipses(cubit,n=1)
data(bock)
responses <- table2df(bock.table[,2:6],count=bock.table[,7],labs= paste("lsat6.",1:5,sep=""))
describe(responses)

psych

Procedures for Psychological, Psychometric, and Personality Research

v2.1.3
GPL (>= 2)
Authors
William Revelle [aut, cre] (<https://orcid.org/0000-0003-4880-9610>)
Initial release
2021-03-21

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.