3

Here is the specified data frame which i am trying to compute Percentage in group_by function ,

df <- data.frame(Tag = c(1 ,1 ,1 ,1 ,1 ,2 ,2 ,2 ,2 ,2),
       YPred = c("L1", "L2" ,"L3", "L4", "L5", "L1", "L2", "L3", "L4", "L5"),
       Long = c(1004 , 544 , 545 , 282  ,  1 ,2068 ,3006 ,3711 ,2342 ,  33),
       Medium = c(108, 252, 211, 149,   0,  17, 110, 248, 341,   4),
       short = c(58, 118, 131,  73,   4,   0,  43, 150, 189,2),
       Urgent = c(5, 70, 65, 24 , 5 ,22 ,18, 31 ,96,  2))

Code to achieve Percentage group_by

library(dplyr)
group_by(df, Tag) %>%
mutate_at(.vars = vars(Long:Urgent),
          .funs = funs(. / sum(., na.rm = TRUE)))

Getting Error when executing inside reactive function of Shiny ,but i am execute on R console properly.

Error Message
argument ".cols" is missing, with no default

Nabi Shaikh
  • 787
  • 1
  • 6
  • 26

1 Answers1

1

@nabi.shaikh Error is not in Code , the version which i am for dplyr is older one which i identified.

> getOption("repos")
                                        CRAN 

"https://mran.microsoft.com/snapshot/2017-05-01" CRANextra "http://www.stats.ox.ac.uk/pub/RWin"

Further i updated the dplyr package by repository from recent cran with below . And problem was solved .

install.packages("dplyr", repos = "https://cran.rstudio.com/")
Nabi Shaikh
  • 787
  • 1
  • 6
  • 26