Regarding Error in creating summary

the data frame is like
dataa<-data.frame(
aa = c("q","r","y","v","g","y","d","s","n","k","y","d","s","t","n","u","l","h","x","c","q","r","y","v","g","y","d","s","n","k","y","d","s","t","n","u","l","h","x","c"),
col1=c(1,2,3,2,1,2,3,4,4,4,5,3,4,2,1,2,5,3,2,1,2,4,2,1,3,2,1,2,3,1,2,3,4,4,4,1,2,5,3,5),
col2=c(2,1,1,7,4,1,2,7,5,7,2,6,2,2,6,3,4,3,2,5,7,5,6,4,4,6,5,6,4,1,7,7,2,7,7,2,3,7,2,4)
)

and i trying to create summary for average,mean, percentile

dataset <-  dataa
grp_var <-  "aa"
var <-  "col1"
footer <-  "SS"




grp_var <- enquo(grp_var)
var <- enquo(var)

bygrps_table<-dataset%>%filter(!is.na(!!var),!is.na(!!grp_var)) %>%
  select(!! grp_var, !!var) %>%
  group_by(!! grp_var) %>% 
summarise(
  q25 = round(quantile(!! var,  type=6, probs = seq(0, 1, 0.25), na.rm=TRUE)[2],digits = 1),
  Median =round(quantile(!! var, type=6, probs = seq(0, 1, 0.25), na.rm=TRUE)[3],digits = 1),
  Average = round( mean(!! var, na.rm=TRUE),digits = 1),
  q75 = round(quantile(!! var, type=6, probs = seq(0, 1, 0.25), na.rm=TRUE)[4],digits = 1) ,
  N = sum(!is.na(!!var)))

its giving error :-
Error in round(quantile(~"col1", type = 6, probs = seq(0, 1, 0.25), na.rm = TRUE)[2], :
non-numeric argument to mathematical function

why its giving if column class is numeric

thanks for the reprex, it helped me to quickly look at your situation.

var <-  "col1"

should be either

var <- sym("col1")
#or
var <- col1

and the rest of your code would work to make the bygrps_table

thanks, i forgot to parse expression,
grp_var <- rlang::parse_expr(grp_var)

it works for me thanks....but yours also working

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.