R base
functions
table
table
is a function used to build a contingency table, which is a table that shows counts for categorical data, from one or more categories. prop.table
is a function that accepts table
output, returning proportions of the counts.
Examples
Show how times each brand of ice cream appears, in each of the two files: products.csv and reviews.csv
Click to see solution
# read in the products file
products <- read.csv("/anvil/projects/tdm/data/icecream/combined/products.csv")
table(products$brand)
# read in the reviews file
reviews <- read.csv("/anvil/projects/tdm/data/icecream/combined/reviews.csv")
table(reviews$brand)
# products.csv bj breyers hd talenti 57 69 70 45 # reviews.csv bj breyers hd talenti 7943 5007 4655 4069