What is the ftable() function in R?

Overview

ftable(), short for "flatten table," is a function in R that creates a flat contingency table.

Syntax

ftable(x, ...)
Syntax for the ftable() function

Parameter value

The ftable() function takes the parameter value x, .... This represents R objects that can be interpreted as a list or a factor.

Example

# cretaing R objects
a = c("AAA", "AAA", "BBB", "AAA", "AAA", "CCC", "BBB", "BBB", "AAA")
b = c("yyy", "yyy", "qqq", "yyy", "qqq", "iii", "yyy", "qqq", "iii")
c = c("___", "###", "___", "___", "###", "___", "___", "###", "???")
# implementing the ftable() function
mytable <- ftable(a, b, c)
# printing the table
mytable

Explanation

  • Lines 2-4: We create R objects: a, b, and c.
  • Line 7: We use the ftable() function to create a flattened table of the R objects. The result is assigned to a variable, mytable.
  • Line 10: We print the mytable variable.

Free Resources