-1
RYpovertime<-c("RY") %>%
tq_get(get = "stock.prices", from = "2000-01-01")%>%
select(symbol, date, adjusted)

RY_daily_returns <- RYpovertime %>%
  tq_mutate(select = adjusted,
            mutate_fun = periodReturn,
            period = "daily",
            col_rename = "RY_returns")

ie. returns of 10% are recorded as 0.01 in the returns column, how can I change this decimal to a whole number?

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Oli11
  • 1
  • Can you just multiply the number by 100? You seem to be using some non-base R functions here so it's not clear what packages you are using. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jun 10 '21 at 04:40
  • Thanks @MrFlick, I'm very new to this and yes I can just multiply it by 100. I'm not sure how to include a reproducible example but can you suggest the code to multiply by 100? I tried a few options and none were recognised. – Oli11 Jun 10 '21 at 04:51
  • 1
    Well I don't have any idea what the `tq_mutate` function is or what it returns so it's difficult to help you. If we can't copy/paste the code into R to run and test it, it's difficult to help you. Make sure all the dependencies are explicitly listed in your question. – MrFlick Jun 10 '21 at 04:57
  • How can I make it easier to interpret? I copied this from my work in r. I used tq_mutate to add the column for returns. From that information can you suggest an alternative way to code a table with date, adjusted price and daily returns? I apologise if I am poor at explaining and bad with terminology. – Oli11 Jun 10 '21 at 05:04

1 Answers1

1

You can simply add %>% mutate(RY_returns = RY_returns*100) or whatever number you would like. The tidyquant package has been designed to be used with the tidyverse.

So to be clear:

RY_daily_returns <- RYpovertime %>%
     tq_mutate(select = adjusted,
               mutate_fun = periodReturn,
               period = "daily",
               type = "log",
               col_rename = "RY_returns") %>%
     mutate(RY_returns = RY_returns*100)