Re: [R] Group by and duplicate a value/dplyr

2021-05-11 Thread Gerrit Eichner
Hello, Elahe, you were, of course, supposed to insert my suggested code-snippet into you code and test it therein ... Regards -- Gerrit - Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@m

Re: [R] Group by and duplicate a value/dplyr

2021-05-11 Thread Elahe chalabi via R-help
Hello Gerit mutate(MinValue = min(Value[Value != 0]) )  or  mutate(MinValue = sort(unique(Value))[2]) only mutates one value which is 100, it doesnt mutate minimum Value != 0 per group by element On Tuesday, May 11, 2021, 01:26:49 PM GMT+2, Gerrit Eichner wrote: Homework? Try ma

Re: [R] Group by and duplicate a value/dplyr

2021-05-11 Thread Rui Barradas
Hello, This can be done by getting the min of Value[Value != 0]. In the code that follows I have named the expected output df2 and assigned the result to df3 and df4. library(dplyr) df3 <- df %>% group_by(Department,Class) %>% mutate(flag = Value != 0, MinValue = min(Value[flag]) ) %

Re: [R] Group by and duplicate a value/dplyr

2021-05-11 Thread Gerrit Eichner
Homework? Try maybe mutate(MinValue = min(Value[Value != 0]) ) or mutate(MinValue = sort(unique(Value))[2]) Hth -- Gerrit - Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@math.uni-gie