Clueless about this error: wrong sign in 'by' argument

余生颓废 提交于 2020-01-14 03:43:08

问题


I have the following dataset:

 >k1[1:10,]
       id  web_name first_name second_name   position     date team1 team2 game_week points home_away team_scored team_conceded minutes goals assists
    1   1 Fabianski     Lukasz   Fabianski Goalkeeper 17/08/13   ARS   AVL         1      0         H           1             3       0     0       0
    2   1 Fabianski     Lukasz   Fabianski Goalkeeper 24/08/13   ARS   FUL         2      0         A           3             1       0     0       0
    3   1 Fabianski     Lukasz   Fabianski Goalkeeper 01/09/13   ARS   TOT         3      0         H           1             0       0     0       0
    4   1 Fabianski     Lukasz   Fabianski Goalkeeper 14/09/13   ARS   SUN         4      0         A           3             1       0     0       0
    5   1 Fabianski     Lukasz   Fabianski Goalkeeper 22/09/13   ARS   STK         5      0         H           3             1       0     0       0
    6   1 Fabianski     Lukasz   Fabianski Goalkeeper 28/09/13   ARS   SWA         6      0         A           2             1       0     0       0
    7   1 Fabianski     Lukasz   Fabianski Goalkeeper 06/10/13   ARS   WBA         7      0         A           1             1       0     0       0
    8   1 Fabianski     Lukasz   Fabianski Goalkeeper 19/10/13   ARS   NOR         8      0         H           4             1       0     0       0
    9   1 Fabianski     Lukasz   Fabianski Goalkeeper 26/10/13   ARS   CRY         9      0         A           2             0       0     0       0
    10  1 Fabianski     Lukasz   Fabianski Goalkeeper 02/11/13   ARS   LIV        10      0         H           2             0       0     0       0

When I run the code:

 > k2<- as.data.frame(k1 %>% group_by(id) %>%
 mutate(min1 = lag(minutes, default=NA)) %>%
 mutate(min3 = rollapply(min1,width=3,mean, align= "right", fill=NA)))

I receive the error:

Error: wrong sign in 'by' argument

However grouping by team1 via this code just works fine:

> k2<- as.data.frame(k1 %>% group_by(team1) %>%
   mutate(min1 = lag(minutes, default=NA)) %>%
   mutate(min3 = rollapply(min1,width=3,mean, align= "right", fill=NA)))

Pretty clueless why this is happening. Any help is appreciated.


回答1:


It can have different reasons, But simply it can happen if you pass a NULL dataframe to rollapply function

Also consider the using of zoo() as

rollapply(Zoo(min1),width=3,mean, align= "right", fill=NA)


来源:https://stackoverflow.com/questions/31896113/clueless-about-this-error-wrong-sign-in-by-argument

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!