Hercules Apergis
Hercules Apergis

Reputation: 421

Plot percentages in R

I have a data set in the following form 2 columns, x and s:

x<-c(9,13,6,8,10,4,14,8,11,7,9,7,16,9,9,11,13,15,13,10,11,6)
s<-c(1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0)

For which I want to plot the percentages of (success = 1) for each level of x. There are many more rows with the same score for x and in various cases the s=1 or s=0.

Thank you so much for your time.

The plot made using Daniel's aid is this: enter image description here

Upvotes: 2

Views: 887

Answers (1)

Daniel Bachen
Daniel Bachen

Reputation: 119

Use the aggregate function and mean functions aggregate(s ~ x, FUN = mean). This can be plotted with plot(aggregate(s ~ x, FUN = mean), type = "h")

Upvotes: 3

Related Questions