I am trying to use the tapply function to get some output for a variable x.
a = c(1,2,3,4)
b = c(5,3,8,1)
c = c(1,1,2,2)
df = data.frame(a,b,c)
fun <- function(data,var){
x <- tapply(data$b,data$var,function(x) return(x))
return(x)
}
fun(df,c)
However, when I run this I get the following error:
Error in tapply(data$b, data$var, function(x) return(x)) :
arguments must have same length
I have already tried using the eval(parse(text = paste approach with no luck. Thanks for the help!