[R] [FORGED] Grouping Question

Rolf Turner r@turner @end|ng |rom @uck|@nd@@c@nz
Sun Mar 22 09:23:03 CET 2020


On 22/03/20 8:44 pm, Deepayan Sarkar wrote:

> Another possible approach is to use split -> lapply -> rbind, which I
> often find to be conceptually simpler:
> 
> d <- data.frame(Serial = c(1, 1, 2, 2, 2, 3, 3),
>                  Measurement = c(17, 16, 12, 8, 10, 19, 13))
> 
> dlist <- split(d, d$Serial)
> dlist <- lapply(dlist, within,
> {
>      Serial_test <- if (all(Measurement <= 16)) "pass" else "fail"
>      Meas_test <- ifelse(Measurement <= 16, "pass", "fail")
> })
> do.call(rbind, dlist)

Yes!!! Much sexier than my clumsy hack-and-grind approach!

cheers,

Rolf

-- 
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-help mailing list