Morning Bill, I take it this is dplyr? You might try: tmp1 <- HCPC %>% group_by(HCPCSCode) %>% summarise(Avg_AllowByLimit = mean(Avg_AllowByLimit[which(Avg_AllowByLimit!=0 & AllowByLimitFlag == TRUE)]))
The code above gives "NaN" for cases where AllowByLimitFlag == FALSE. Maybe this is the answer you desire, otherwise you can filter out "NaN" rows. Cheers, Bill. W. Michels, Ph.D. On Wed, May 22, 2019 at 5:41 AM Bill Poling <bill.pol...@zelis.com> wrote: > > Good morning. > > #R version 3.6.0 Patched (2019-05-19 r76539) > #Platform: x86_64-w64-mingw32/x64 (64-bit) > #Running under: Windows >= 8 x64 (build 9200) > > I need a calculated field For the Rate of Avg_AllowByLimit where the > Allowed_AmtFlag = TRUE BY Each Code > > I have almost got this. > > #So far I have this > tmp1 <- tmp %>% > group_by(HCPCSCode) %>% > summarise(Avg_AllowByLimit = > mean(Avg_AllowByLimit[which(Avg_AllowByLimit!=0)])) > > # But I need Something like that + This > > WHERE AllowByLimitFlag == TRUE > > I cannot seem to get it in there correctly > > Thank you for any help > > WHP > > #Here is some data > HCPCSCode Avg_AllowByLimit AllowByLimitFlag > 1 J1745 4.50 FALSE > 2 J9299 18.70 FALSE > 3 J9306 14.33 FALSE > 4 J9355 7.13 FALSE > 5 J0897 8.61 FALSE > 6 J9034 3.32 FALSE > 7 J9034 3.32 FALSE > 8 J9045 15.60 FALSE > 9 J9035 2.77 TRUE > 10 J1190 3.62 FALSE > 11 J2250 879.10 FALSE > 12 J9033 2.92 FALSE > 13 J1745 4.50 TRUE > 14 J2785 12.11 FALSE > 15 J9045 15.60 FALSE > 16 J2350 7.81 FALSE > 17 J2469 10.65 TRUE > 18 J2796 6.27 FALSE > 19 J2796 6.27 FALSE > 20 J9355 7.13 FALSE > 21 J9045 15.60 FALSE > 22 J2505 2.73 FALSE > 23 J1786 2.81 FALSE > 24 J3262 3.26 FALSE > 25 J0696 168.87 FALSE > 26 J0178 1.52 TRUE > 27 J9271 5.55 FALSE > 28 J3380 80.99 FALSE > 29 J9355 7.13 TRUE > 30 J2469 10.65 FALSE > 31 J9045 15.60 FALSE > 32 J1459 3.64 FALSE > 33 J9305 8.74 FALSE > 34 J9034 3.32 FALSE > 35 J9034 3.32 FALSE > > Confidentiality Notice This message is sent from Zelis. ...{{dropped:13}} > > ______________________________________________ > R-help@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. ______________________________________________ R-help@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.