I have a S4 object which inherits from a data.frame, but when I try to use aggregate on it, it does not work unless I explicitly pass the data.frame part of the object. Let me ilustrate it with an example:
setOldClass("data.frame")
setClass("DataFrame",
slots = c(
data1 = "data.frame",
data2 = "data.frame"
),
contains = "data.frame")
df <- data.frame("a" = 1:6,
"b" = 2:7,
"c" = rep(c(1,2), each = 3))
df <- new("DataFrame", df)
Now if I execute aggregate(a ~ c, FUN = mean, data = df) it produces the following error:
Error in terms.formula(formula, data = data) : 'data' argument is of the wrong type
Why is that? df inherits from data.frame, so that should not be a problem.
I know that executing aggregate(a ~ c, FUN = mean, data = S3Part(df)) works as I want, but I would like to know why calling the data directly from df don't.