countOrSum | R Documentation |
Count or Sum Up Values Within Groups of rows
countOrSum(x, by = NULL, sum.up = NULL)
x |
data frame |
by |
vector of names of columns in |
sum.up |
name of column in |
object of class xtabs
with as many dimensions as there are
values in by
# Create a data frame with example data
x <- data.frame(
Group = rep(c("A", "B", "C"), 4),
Even = rep(c(FALSE, TRUE), 6),
Value = seq_len(12)
)
# Count the number of rows for each group
countOrSum(x, "Group")
countOrSum(x, c("Group", "Even"))
# Sum up the values in column "Value" for each group
countOrSum(x, "Group", sum.up = "Value")
countOrSum(x, c("Group", "Even"), sum.up = "Value")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.