This is a simple question but I could not figure out how to use prop.table for this and I need this functionality very very often.
I have data like this
> library(ggplot2)
> #sample data
> head(tips,3)
total_bill tip sex smoker day time size
1 17 1.0 Female No Sun Dinner 2
2 10 1.7 Male No Sun Dinner 3
3 21 3.5 Male No Sun Dinner 3
> #how often there is a non-smoker
> table(tips$smoker)
No Yes
151 93
> #how many subjects
> nrow(tips)
[1] 244
And I need to know percentage of smokers vs. non smokers
Something like this (ugly code):
> #percentage of smokers
> options(digits=2)
> transform(as.data.frame(table(tips$smoker)),percentage_column=Freq/nrow(tips)*100)
Var1 Freq percentage_colum