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 objectsa = 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() functionmytable <- ftable(a, b, c)# printing the tablemytable
Explanation
- Lines 2-4: We create R objects:
a,b, andc. - 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
mytablevariable.