TextToTable: Converts String To a Table

Description Usage Arguments Value Author(s) See Also Examples

View source: R/DescTools.r

Description

Try to convert a string to a table, by first creating a data frame using read.table. This can then be coerced to a matrix first, and subsequently to a table. The names of the dimensions can be specified.

Usage

1
TextToTable(x, dimnames = NULL, check.names = FALSE, ...)

Arguments

x

the string to be interpreted as table.

dimnames

the names of the dimensions.

check.names

passed on to read.table and determines, if invalid column names should be adapted to valid ones. The default here is changed to FALSE.

...

the dots will be passed to the function read.table and can be used for example to specify header, sep and row.names arguments.

Value

a table

Author(s)

Andri Signorell <andri@signorell.net>

See Also

read.table, as.table, as.matrix

Examples

1
2
3
4
5
6
txt <- "
    Democrat, Independent, Republican
  M, 762, 327, 468
  F, 484, 239, 477"

(tab <- TextToTable(txt, header=TRUE, sep=",", dimnames=c("gender", "party")))

Example output

      party
gender Democrat Independent Republican
     M      762         327        468
     F      484         239        477

DescTools documentation built on June 17, 2021, 5:12 p.m.