without knowing specifics of your problem. I can offer a helpful solution that could get you thinking in the right direction about how to subset a data.frame by one category and get the count/sum of another:
library(dplyr)
library(magrittr)
age <- c(1, 2, 3, 4, 5)
name <- c("Jasmine","Jane", "Jake", "Julie", "Jenna")
grade <- c("A", "A", "B", "B", "C")
gender <- c("F", "F", "M", "F", "F" )
pet <- c(T, F, F, F, T)
df <- data.frame(age, name, grade, gender, pet)
colnames(df) <- c("age", "name", "grade", "gender", "pet")
df %>%
group_by(pet) %>%
summarise(count = sum(age))
Your output would be:
Source: local data frame [2 x 2]
pet count
(lgl) (dbl)
1 FALSE 9
2 TRUE 6
... And you could easily put that into a bar graph if that is what you are indeed looking for! I used this technique recently to summarise
a very large data frame with many levels per factor and I needed the count based on another co-variate for generating bar graphs and I'm new-ish too!