1 | initial version |
To create a table using a frequency column to count occurrences, follow these steps:
dimnames
argument.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.