Hey! I'm new on R and everytime I aplly this fuction to get the assets weekly return from the monthly return that I already have, a error appears and I think it is because my data period it is separate by year and month colunes... but I'm not so sure about this and I don't know how to change the period from two colunes of year and month to just one colune with the normal date...
Hi!
To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
so I read this guide but I'm still not abble to do the "reprex"
Can I post here a print from my R studio screen to help you understand my question?
Ideally, no. Screenshots are considered a bad practice here, post formatted code instead. Here is how to do it:
Although, if you don't have another option, they are better than nothing.
ok... I think I did it! Here is a example of my data frame and the function from tidyquant (tq_transmute) that I apply to it
ticker <- c("AALR3")
year<- c(2017)
month<- c(1,2,3,4,5,6)
price <- c(13.747508,12.564078,15.414171,18.323436,17.485173,17.297797)
monthly_return<- c(-0.048464171,-0.086083238,0.226844580,0.188739634,-0.045748134,-0.010716279)
data<- data.frame(ticker,year,month,price,monthly_return)
#Executing the function to get the weekly return
library (tidyquant)
weekly_retun <- data %>%
tq_transmute(
select = monthly_return,
mutate_fun = periodReturn,
period = "weekly",
col_rename = "weekly_return")
And always I run this code I see this error:
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
namespace ‘tibble’ 3.1.6 is already loaded, but >= 3.1.7 is required
Sorry for the bad code and bad English but I hope it was understandable
This specific error message is asking you to update the tibble
package. Restart your R session and try to update it with this command:
install.packages("tibble")
Do you get any error messages while doing so?
This is true though, the periodReturn
function requires a date
column. You can construct a proper date
column this way although I'm not sure it produces the expected output.
weekly_retun <- data %>%
mutate(date = ymd(paste(year, month, "1", sep = "-"))) %>%
tq_transmute(
select = monthly_return,
mutate_fun = periodReturn,
period = "weekly",
col_rename = "weekly_return")
ok... I just run this code to change the date but the same error appeared
Anyways, thank you so much for the help
If you are getting the exact same error, then you haven't updated the tibble
package successfully. Please post the complete console output you get when you run this command so I can help you with that.
install.packages("tibble")
Try to upload this libarary. Check information about remotes
install.packages('remotes')
library(remotes)
#Current Version Installed
packageVersion("tibble")
[1] "3.1.6"
#Installing version 3.1.7
remotes::install_version("tibble", version = "3.1.7")
#Check the installed version of the upload package
packageVersion("tibble")
[1] ‘3.1.7’
Next restart and run the script.
I did this but the R studio returns a warning message:
Warning messages:
1: In missing_devel_warning(pkgdir) :
Package tibble has compiled code, but no suitable compiler(s) were found. Installation will likely fail.
Install Rtools (https://cran.r-project.org/bin/windows/Rtools/).Then use the pkgbuild package, or make sure that Rtools in the PATH.
it seems that I must install R tools because when I run the code to install the tibble package the R studio shows the follow warning message:
Warning messages: 1: In missing_devel_warning(pkgdir) : Package tibble has compiled code, but no suitable compiler(s) were found. Installation will likely fail. Install Rtools (https://cran.r-project.org/bin/windows/Rtools/).Then use the pkgbuild package, or make sure that Rtools in the PATH.
sorry, I kinda lost about this
Probably you need to install RTools but I can't tell for sure since you haven't posted the complete console output and I don't have enough information to work with.
This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.