0

The code aggregate(df$var, list(df$id), runs.test) returns the test statistic (standard normal) of the variance of a given function.

Normally, the code runs.test(data)$p.value gives you the p-value. But aggregate(df$var, list(df$id), runs.test(df$var)$p.value) gives the the error:

Error in match.fun(FUN) : 
  'runs.test(df$var)$p.value' is not a function, character or symbol

How can I use aggregate to give me the p-value?

1
  • 1
    a reproducible example would be nice. But you might try aggregate(df$var, list(df$id), function(x) runs.test(x)$p.value) Commented Oct 11, 2017 at 22:21

1 Answer 1

1

You will have to declare an anonymous function.

aggregate(var ~ id, data = df, FUN = function(x) runs.test(x)$p.value)

By the way, when you use functions that are not base R functions like runs.test, always include a call to library(pkgname) as the first line of code.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.