Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dplyr mutate in zoo object

Tags:

r

dplyr

zoo

I was trying to apply the dplyr mutate in zoo object. But, it generated an error:

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

I googled and saw that it has not been yet resolved. A recent discussion on this is here.

I would appreciate if any one could help me in this regard.

like image 306
user227710 Avatar asked Nov 24 '25 18:11

user227710


1 Answers

zoo has a transform method:

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

transform(z, a = a + 1, c = a + b)

giving:

  a b c
1 2 4 5
2 3 5 7
3 4 6 9

or using z from above, the following gives the same result:

library(magrittr)
z %>% transform(a = a + 1, c = a + b)

Next time please provide sample code, inputs and expected outputs.

like image 89
G. Grothendieck Avatar answered Nov 27 '25 10:11

G. Grothendieck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!