I need to create a frequency table by extracting multiple variables from another dataframe.
For example I have a dataframe with the following info
Product Result Location Source Year Month
I want to create a frequency table based on positive detection (i.e. result 1 ) similar to a pivot table in excel. For example
Source Product Location 2008 2009 2010 2011
where the freq of detection for each year is calculated based on total count of the category.
The end result is I want to plot a facet grid based on x= year, y = freq, color = source, facet grid = sample
I could do the ggplot using count of 1s but how do i do it using freq instead so that the denominator can be taken into account?
My actual data has 20,000+ rows.
sorry i couldn't add in the codes somehow.
Thank you.
df %>% group_by(Species, Petal.Width) %>% summarise(COUNT = n()) %>% ungroup() %>% mutate(PERCENT = COUNT/sum(COUNT))
– Ryan Mortonfilter(COUNT == 1)
, – Ryan Mortondf %>% group_by(Species, Petal.Width) %>% summarise(COUNT = n()) %>% ungroup() %>% mutate(PERCENT = COUNT/sum(COUNT)) %>% filter(COUNT == 1) %>% summarise(COUNT_1 = sum(PERCENT)
– Ryan Morton