ns am attempting to reproduce one of the instances in the dplyr package but am acquiring this error message. Ns am expecting to see a new column n created with the frequency of each combination. What am i missing? ns triple confirm that the parcel is loaded.

You are watching: Error: this function should not be called directly

library(dplyr)# summarise peels turn off a solitary layer that groupingby_vs_am Error in n() : This duty should no be referred to as directly



I suspect you have actually dplyr and also plyr invited in the very same session. Dplyr is no plyr. Ddply is no a role in the dplyr package.

Both dplyr and also plyr have the functions summarise/summarize.

Look in ~ the outcomes of conflicts() to check out masked objects.



As pointed out by the previous answer, girlfriend may have actually a conflict in between plyr and dplyr. You have the right to to run this command to unload the plyr package.

detach("package:plyr", unload=TRUE) then you can proceed as expected.

library(dplyr) ...summarise(n = n())


To avoid confusions through masking functions, that is clean to usage the "package::function" specification, like instance below:

In an additional case, this error arisen in the adhering to code.

See more: Antonio De Mendoza - Viceroy : Biography & Facts

library(dplyr) # dplyr 0.5.0library(lazyeval)df % group_by_(g) %>% summarise_( n = n(), amount = interp(~sum(col, na.rm = TRUE), col = as.name(g)) )# Error in n() : This role should no be referred to as directlyIt can be fixed as follows.

df %>% group_by_(g) %>% summarise_( n = "n()", sum = interp(~sum(col, na.rm = TRUE), col = as.name(g)) )# A tibble: 3 × 3# group n sum# # 1 1 1 1# 2 2 2 4# 3 3 3 9
Faced similar issue if executing password as per pointed out blog and also then run systems in detach("package:plyr", unload=TRUE)

Blog : https://www.analyticsvidhya.com/blog/2017/09/comparative-stock-analysis/

Master_Data_AutoCorrelations% gather(key = "lag", value = "lag_value", -c(Stock,Date, Close)) %>% mutate(lag = str_sub(lag, start = 5) %>% as.numeric) %>% group_by(Stock, lag) %>% summarize( cor = cor(x = Close, y = lag_value, use = "pairwise.complete.obs"), cutoff_upper = 2/(n())^0.5, cutoff_lower = -2/(n())^0.5 )Post running detach,when over code was rerun it operated fine though obtained warning message as per below ,not sure whether plyr acquired unloaded or not.And exactly how is the password executed effectively ?

Warning message:‘plyr’ namespace cannot be unloaded: namespace ‘plyr’ is imported through ‘reshape2’, ‘scales’, ‘broom’, ‘ggplot2’ so can not be unloaded