I setup to use a loop to go v a few 100 columns and also calculate a median and also count against a set of variables.

You are watching: Error: n() should only be called in a data context

Code : grp_var % select_(grp_var,voi)%>% group_by_(grp_var)%>% summarise_(Median_Value = median(voi),Count = n())

Error : Error in n() : This function should not be dubbed directly

I challenge this error when i use summarise_ and don't face any issues in ~ all as soon as i use summarise.

I understand that the function call come n() is just the error message yet when dubbed within a dplyr role it return the row count.

Am i just being dumb about this or is this a pest ?


9 comments
share
save
hide
report
88% Upvoted
Log in or sign up to leave a comment
Log InSign Up
Sort by: best


*

level 1
· 4y
Try this:

grp_var % select(!!grp_var, !!voi) %>% group_by(!!grp_var) %>% summarise(med_val = median(!!voi), counting = n())It looks prefer all those underscore attributes like summarise_ are deprecated as of dplyr variation 0.7. Here's the (I guess) much more tidyverse-consistent method for taking care of these situations


5
Reply
Share
ReportSave
level 2
Op · 4y

Thanks a lot, this helps. I have to read up the brand-new documentation :(


1
Reply
Share
ReportSave
level 1
Op · 4y · edited 4y

So it appears 4476mountvernon.com took out _ after ~ every dplyr role . That should have actually been "select_'","group_by_'" and also "summarise_"

Edit : yeah 4476mountvernon.com doesn't prefer underscores :

Edit 2 : There are no conflicts for summarise duty as well.

See more: Did Tom Hanks Hair Transplant S, Did Tom Hanks Have A Hair Transplant Treatment


2
Reply
Share
ReportSave
level 2
· 4y

When you're editing and enhancing your post, take a look at the "formatting help" connect at the bottom that the edit window. It describes how to format code.


2
Reply
Share
ReportSave
Continue this thread 


level 2
· 4y
Surround it in backticks and_it_will_render_the_text_as_code


1
Reply
Share
ReportSave
level 1
· 4y

Do you have plyr loaded?


2
Reply
Share
ReportSave
level 2
Comment deleted by user · 4y
Continue this thread 


level 2
Op · 4y
Nope, no conflicts on summarise


1
Reply
Share
ReportSave
r/rstats
Welcome to rstats
58.5k

Members


88

Online


Created Oct 2, 2009
Join
*
*
*
*

*

Top posts august 11th 2017Top write-ups of august, 2017Top posts 2017
help4476mountvernon.com coins4476mountvernon.com premium4476mountvernon.com gifts
aboutcareerspressadvertiseblogTermsContent policyPrivacy policyMod policy
Back to Top