Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create a table using a frequency column to count occurrences, follow these steps:

  1. Start by creating a vector or data frame containing the data you want to count.
  2. Use the table() function to create a tally of the frequency of each value in your data.
  3. You can optionally name your table using the dimnames argument.
  4. Print your table to view the final result.

Here is a code example:

# create a vector to count
fruit <- c("apple", "banana", "orange", "orange", "orange", "apple", "kiwi", "banana", "banana", "kiwi")

# use the table() function to count the frequency of each value
fruit_freq <- table(fruit)

# optionally name the table using dimnames argument
dimnames(fruit_freq) <- list("Fruit Type" = names(fruit_freq), "Frequency" = "Count")

# print the final table
print(fruit_freq)

This will output the following table:

         Frequency
Fruit Type Count
     apple     2
    banana     3
      kiwi     2
    orange     3

The table shows how many times each value (fruit type) occurred in the original dataset.