简体   繁体   English

R中的tapply功能

[英]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. data$td是具有2个类别的字符变量。

But this does not work getting the error: 但这无法得到错误:

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

Thanks a lot! 非常感谢!

In tapply the first argument is numeric and the second is a factor and the third the function you use. 在tapply中,第一个参数是数字,第二个参数是因子,第三个参数是您使用的函数。

If you want to do a numeric averaging on td the form is tapply(data$td, your-factor, fonction.mm). 如果要对td进行数字平均,则格式为tapply(data $ td,your-factor,fonction.mm)。

Also what is your "poids" ? 还有什么是你的“蠢蛋”?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM