0

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!

rcs
  • 67,191
  • 22
  • 172
  • 153
aleeyah
  • 1
  • 1
  • 3

1 Answers1

1

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" ?

Xachriel
  • 313
  • 2
  • 7
  • Thanks I have change the syntax but now i get : Error: cannot allocate vector of size 2.1 Mb / poids is the chosen time of my average mean – aleeyah Jun 17 '13 at 09:03
  • R doesn't really free up memory. Use rm(object1, object2, ...) to remove those object which use alot of memory. Or start a new R session. Also choose the 64bit version of R if you have more then 4gb of memory avaivable. If these don't help you need to improve your code or get more memory to your computer (which probably isn't the issue). – Xachriel Jun 17 '13 at 09:21