Mark -
Here's one way to get the percentages you want. Suppose your
data frame is called df:
correct = subset(as.data.frame(with(df,table(date,region,correct))),
correct=='yes')
all = as.data.frame(with(df,table(date,region)))
names(all)[3] = 'Total'
both = merge(correct,all)
both$Pct = both$Freq / both$Total * 100
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spector at stat.berkeley.edu
On Mon, 27 Sep 2010, Mark Noworolski wrote:
> What I'm trying to do is to figure out how to create lattice charts of
> %right by region, or alternatively, by date from a dataset of observations
> that looks something like this:
>
> date,location,region,correct
> 2010-09-10,a,r1,yes
> 2010-09-10,a,r1,yes
> 2010-09-10,a,r1,no
> 2010-09-11,a,r1,yes
> 2010-09-01,b,r1,yes
> 2010-09-02,b,r1,no
> 2010-09-01,a,r2,yes
> 2010-09-02,a,r2,no
> 2010-09-02,a,r2,yes
> 2010-09-02,a,r2,no
> 2010-09-03,a,r2,yes
> etc.
>
> I get that I can do something like:
> tmp<-xtabs(~correct+region+date,t)
>
> This gets me partway by providing counts. The thing that I'm missing
here is
> how get from this to being able to plot, for example, a family of
> lattice-style curves that looks something like:
>
> %right (by region) on the y axis, with the x axis being the date
>
> I've tried something
> like barchart(xtabs(~correct+region+date,t),stack=F,auto.key=T) which gets
> me close with the counts of observations, but I really am after the
> proportions evaluated by region, not the counts.
>
> I don't see how to marginalize prop.table properly to give me my answer
> either (if, in region 1, on a given day, all are correct - then that number
> should be 100% on the chart/graph, independent of what happened in region
> 2)- but I'm quite sure that I'm missing something obvious here.
>
> Any suggestions would be appreciated.
> Thanks,
> mark
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>