Thank you Jeff!

WHP

From: Jeff Newmiller <jdnew...@dcn.davis.ca.us>
Sent: Wednesday, May 22, 2019 10:06 AM
To: r-help@r-project.org; Rui Barradas <ruipbarra...@sapo.pt>; Bill Poling 
<bill.pol...@zelis.com>; r-help (r-help@r-project.org) <r-help@r-project.org>
Subject: Re: [R] Help with R coding

Generally more efficient to filter before grouping.

Note that summarize clears out whatever isn't mentioned in it, so the 
subsetting currently being done in the mean call could also be done in the 
pre-filter step and you can avoid filtering other columns and then discarding 
them by limiting the operations to only those columns that will be referenced:

tmp1 <- tmp %>%
select( HCPCSCode, Avg_AllowByLimit, AllowByLimitFlag )
filter( AllowByLimitFlag & Avg_AllowByLimit != 0 ) %>%
group_by( HCPCSCode ) %>%
summarise( Avg_AllowByLimit = mean( Avg_AllowByLimit ) )


On May 22, 2019 6:45:39 AM PDT, Rui Barradas <mailto:ruipbarra...@sapo.pt> 
wrote:
>Hello,
>
>Maybe filter the AllowByLimitFlag values first (not tested)?
>
>
>tmp1 <- tmp %>%
> group_by(HCPCSCode) %>%
> filter(AllowByLimitFlag) %>%
> summarise(Avg_AllowByLimit =
>mean(Avg_AllowByLimit[which(Avg_AllowByLimit!=0)]))
>
>
>Hope this helps,
>
>Rui Barradas
>
>
>Às 13:35 de 22/05/19, Bill Poling escreveu:
>> 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
>
>______________________________________________
>mailto: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.

--
Sent from my phone. Please excuse my brevity.

Confidentiality Notice This message is sent from Zelis. This transmission may 
contain information which is privileged and confidential and is intended for 
the personal and confidential use of the named recipient only. Such information 
may be protected by applicable State and Federal laws from this disclosure or 
unauthorized use. If the reader of this message is not the intended recipient, 
or the employee or agent responsible for delivering the message to the intended 
recipient, you are hereby notified that any disclosure, review, discussion, 
copying, or taking any action in reliance on the contents of this transmission 
is strictly prohibited. If you have received this transmission in error, please 
contact the sender immediately. Zelis, 2018.
______________________________________________
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.

Reply via email to