aleeyah
aleeyah

Reputation: 1

tapply function in R

I am trying to apply my moving average function to one variable as follow:

Fonction.mm <- function(x)
{
  filter(x, poids, sides=1, method="conv")
}

numero<-1:nrow(data)
tapply(numero, data$td, Fonction.mm)

data$td which is a character variable with 2 categories.

But this does not work getting the error:

Error in tapply(numero, data$td, Fonction.mm) : 
  arguments must have same length

Thanks a lot!

Upvotes: 0

Views: 3535

Answers (1)

Xachriel
Xachriel

Reputation: 313

In tapply the first argument is numeric and the second is a factor and the third the function you use.

If you want to do a numeric averaging on td the form is tapply(data$td, your-factor, fonction.mm).

Also what is your "poids" ?

Upvotes: 1

Related Questions