The following code runs fine:
library(dplyr)
library(lazyeval)
datatable <- data.frame(f= c("Group1","Group2")
,a = c(100,200)
,b = c(400,500)
,c = c(50000,35000)
,d = c(99000,70000))
datatable %>%
group_by(f) %>%
mutate(p = prop.test(x=c(a, b)
,n=c(c, d)
,alternative = c("two.sided")
,correct = FALSE)$p.value)
However, when put into a function, the code errors:
functionx <- function(datatable, f, a, b, c, d)
{
Table <- datatable %>%
group_by_(f) %>%
mutate_(p = interp(~prop.test(x=c(a, b)
,n=c(c, d)
,alternative = c("two.sided")
,correct = FALSE)$p.value))
}
The error I am receiving reads as follows:
Error: non-numeric argument to binary operator
I've tried writing the function a few different ways (ex. a=as.name(a)). I am new to writing functions (specifically NSE/SE) - any help appreciated.