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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-10-05 11:00:00 +0000
Seen: 14 times
Last updated: Apr 18 '22
How can I include the hours component to a DateTime column using PowerQuery?
Identify commonalities among the strings in a specific column of a DataFrame.
What is the procedure for using Pandas fillna() method with the column's mode?
How can you use linq to choose a specific column from a datatable?