1 Reply Latest reply on May 28, 2019 12:58 PM by Nathan Mannheimer

    Can the Worksheet View and data being sent to R be different?

    rahul.subramanian

      Hi,

      Apologies for the vague question.

      I have a scenario where in I have a set of columns and data which look something like this.

       

      Category
      Product
      Flag
      Category1P1Yes
      Category1P1No
      Category2P1Yes
      Category2P2Yes
      Category2P2No

       

       

      I need to pass this data to R for a pvalue test.

      A colleague of mine has provided me with the script, as I am zero when it comes to R analytics.

       

      The code goes something like this:

      library(dplyr)

      chisq_on_count <- function(n,pid,flag) tryCatch({set.seed(5);chisq.test(xtabs(n~pid+flag,data.frame(n=n,pid=pid,flag=flag,stringsAsFactors=F)), simulate.p.value=T,B =100000)$p.value}, error=function(e) 1)

      df<- data.frame(cat=.arg1,pid=.arg2,flag=.arg3,n=.arg4,stringsAsFactors=F)

      (df %>% group_by(cat) %>% mutate(p_value=chisq_on_count(n,pid,flag)))$p_value

       

      Which I call into a SCRIPT_REAL("Code",ATTR(Category),ATTR(Product),ATTR(Flag),Sum(Number of Records))

       

      But my Business case is to show on worksheet view, P-value at Category level and the user is not bothered with the other fields.

      But for this function to work properly, I need to pass all the fields mentioned in the above formula.

       

      I am attaching a sample workbook (cannot provide you with actual data).

       

      Please have a look and let me know if it is possible.

       

      Regards,

      Rahul S