[R] how to find the mean and sd :(

Charles Determan cdetermanjr at gmail.com
Fri Sep 11 18:17:08 CEST 2015


You are trying to take the mean/sd of an entire data.frame and therefore
you receive an error.  You must do some form of subset and take the mean of
the 'breaks' column.  This can be done a few ways (as with almost anything
in R).

AM.warpbreaks2 <- subset(AM.warpbreaks, breaks <= 30)


mean(AM.warpbreaks$breaks[Am.warpbreaks$breaks <= 30])

or more concisely

with(AM.warpbreaks, mean(breaks[breaks <= 30]))

Again, the main point here is that you need to specify the column when
working with a data.frame object.


On Fri, Sep 11, 2015 at 11:02 AM, Tom Wright <tom at maladmin.com> wrote:

> On Fri, 2015-09-11 at 07:48 -0700, massmatics wrote:
> > AM.warpbreaks<=30
> The above command is not returning what you expected, what part of the
> AM.warpbreaks dataframe is expected to be <= 30?
> Effectively you are using a two stage process.
> 1) Create a logical vector identifying rows in the dataframe with a
> breaks value <= 30
> 2) use the vector in 1. to extract just the rows you are interested in
> and use that to calculate the mean of the breaks column.
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

	[[alternative HTML version deleted]]

More information about the R-help mailing list