-1

I want just Tibbles, but very often I end up with something terrible else. it looks like this:

p <- tibble (idiotic=  c(1,2,3,4,5)) %>% mutate(ma=rollapply(. 
[,1],2,mean,align='right',fill=NA))

and then I end up with a mess like this: enter image description here

It's a nightmare. How do I get a simply tibble out of a messy data structure like this?

  • I'm not sure what you mean. It looks like you are using the `str()` function. Do you simply mean to print the tibble using `print()`? – PLY Apr 11 '21 at 22:21

1 Answers1

0

It looks like the rollapply is creating something funky. Try just converting to numeric after the mutate.

p <- tibble (idiotic=  c(1,2,3,4,5)) %>% 
     mutate(ma=rollapply(.[,1],2,mean,align='right',fill=NA) %>% as.numeric)

str(p)

tibble [5 × 2] (S3: tbl_df/tbl/data.frame)
 $ idiotic: num [1:5] 1 2 3 4 5
 $ ma     : num [1:5] NA 1.5 2.5 3.5 4.5
Joe Erinjeri
  • 1,200
  • 1
  • 7
  • 15