Skip to content

Group by and duplicate a value/dplyr

2 messages · PIKAL Petr, Elahe chalabi

#
I forgot to cc to rhelp.

Petr

Hi
Dunno how to do it by dplyr
I would use ave

df$MinValue <- ave(df$Value, paste(df$Class, df$Department), FUN =
function(x)
min(x[x>0]))

Cheers
Petr
#
Hi Petr,

Thanks for your help! it works perfectly fine.?
On Tuesday, May 11, 2021, 01:36:50 PM GMT+2, PIKAL Petr <petr.pikal at precheza.cz> wrote:
I forgot to cc to rhelp.

Petr


Hi
Dunno how to do it by dplyr
I would use ave

df$MinValue <- ave(df$Value, paste(df$Class, df$Department), FUN =
function(x)
min(x[x>0]))

Cheers
Petr
______________________________________________
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.