dplyr在动物园对象中变异

use*_*710 3 r zoo dplyr

我试图应用dplyr mutatein zoo对象.但是,它产生了一个错误:

Error in UseMethod("mutate") : 
  no applicable method for 'mutate' applied to an object of class "zoo". 
Run Code Online (Sandbox Code Playgroud)

我用谷歌搜索,看到它还没有解决.最近有关于此的讨论就在这里.

如果有人能在这方面帮助我,我将不胜感激.

G. *_*eck 5

动物园有一个transform方法:

library(zoo)
z <- zoo(cbind(a = 1:3, b = 4:6))

transform(z, a = a + 1, c = a + b)
Run Code Online (Sandbox Code Playgroud)

赠送:

  a b c
1 2 4 5
2 3 5 7
3 4 6 9
Run Code Online (Sandbox Code Playgroud)

或者z从上面使用,以下给出相同的结果:

library(magrittr)
z %>% transform(a = a + 1, c = a + b)
Run Code Online (Sandbox Code Playgroud)

下次请提供示例代码,输入和预期输出.