R for Everyone: Advanced Analytics and Graphics (Addison-Wesley Data & Analytics Series) by Jared P. Lander

R for Everyone: Advanced Analytics and Graphics (Addison-Wesley Data & Analytics Series) by Jared P. Lander

Author:Jared P. Lander [Lander, Jared P.]
Language: eng
Format: azw3
Publisher: Pearson Education
Published: 2017-06-14T04:00:00+00:00


Click here to view code image

> tipsByDay <- ddply(tips, "day", plyr::summarize,

+ tip.mean=mean(tip), tip.sd=sd(tip),

+ Length=NROW(tip),

+ tfrac=qt(p=.90, df=Length-1),

+ Lower=tip.mean - tfrac*tip.sd/sqrt(Length),

+ Upper=tip.mean + tfrac*tip.sd/sqrt(Length)

+ )

>

> ggplot(tipsByDay, aes(x=tip.mean, y=day)) + geom_point() +

+ geom_errorbarh(aes(xmin=Lower, xmax=Upper), height=.3)

The use of NROW instead of nrow is to guarantee computation. Where nrow works only on data.frames and matrices, NROW returns the length of objects that have only one dimension.

> nrow(tips)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.