[R] Applying by() when groups have different lengths [RESOLVED]

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Mon Sep 17 22:32:41 CEST 2018


"  I did not pick up on by() doing the splitting for me when I read the
help..."

>From ?by:
"A data frame is split by row into data frames subsetted by the values of
one or more factors, and function FUN is applied to each subset in turn."

I do not understand how it could be more clearly stated than that. Care to
elaborate?
Did you run the examples? You should **always** do so.

-- Bert


On Mon, Sep 17, 2018 at 12:56 PM Rich Shepard <rshepard using appl-ecosys.com>
wrote:

> On Mon, 17 Sep 2018, MacQueen, Don wrote:
>
> > I'm also going to guess that maybe your object rainfall_by_site has
> > already been split into separate data frames (because of its name). But
> > by() does the splitting internally, so you should be passing it the
> > original unsplit data frame.
>
> Don,
>
>    I did not pick up on by() doing the splitting for me when I read the
> help
> file and a few web sites!
>
>    Using the unsplit data.frame did the job; e.g.,
>
> rainfall[, "name"]: Sandy 1.4 NE
> [1] 0.1636066
> ------------------------------------------------------------
> rainfall[, "name"]: Sandy 1.7 SSW
> [1] 0.2021324
> ------------------------------------------------------------
> rainfall[, "name"]: Sherwood 3.3 SE
> [1] 0.1461752
>
>    Now I know how to properly apply by() to an unsplit dataframe. Thanks
> for
> the insightful lesson.
>
> Best regards,
>
> Rich
>
> ______________________________________________
> R-help using 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