Clueless about this error: wrong sign in 'by&#

2019-06-05 13:31发布

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条回答
劳资没心,怎么记你
2楼-- · 2019-06-05 13:48

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)
查看更多
登录 后发表回答