I am trying to create a chart.correlation with the package PerformanceAnalytics. This works great like here:
if(!require("PerformanceAnalytics")) {install.packages("PerformanceAnalytics"); require("PerformanceAnalytics")}
library(PerformanceAnalytics)
#
getSymbols("AMZN",from="2016-01-01",to="2020-05-01")
getSymbols("TSLA",from="2016-01-01",to="2020-05-01")
data1<-cbind(diff(log(Cl(AMZN))),diff(log(Cl(TSLA))))
chart.Correlation(data1)
But as soon as there are special characters I get the following error:
Error: unexpected '^' in "data<-cbind(diff(log(Cl(UTDI.DE))),diff(log(Cl(^"
for the following code:
getSymbols("UTDI.DE",from="2016-01-01",to="2020-05-01")
getSymbols("^MDAXI",from="2016-01-01",to="2020-05-01")
data2<-cbind(diff(log(Cl(UTDI.DE))),diff(log(Cl(^MDAXI))))
chart.Correlation(data2)
Does anyone know how to use the special character here?
Related
I'm trying to run this code to stretch the axes after creating a matrix based on calculated Euclidean distances:
ds_newA <- sqrt((new[1] -A[1]ˆ2 + (3*(new[2]-A[2]))ˆ2)
However, I'm getting an input error in the R console:
Error: unexpected input in "ds_newA <- sqrt((new[1] -A[1])ˆ"
Error: unexpected input in "ds_newB <- sqrt((new[1] -B[1])ˆ"
How should the code for formatted?
As noticed in the SO thread Error: unexpected symbol/input/string constant/numeric constant/SPECIAL in my code :
These errors mean that the R code you are trying to run or source is not syntactically correct. That is, you have a typo.
To fix the problem, read the error message carefully. The code provided in the error message shows where R thinks that the problem is. Find that line in your original code, and look for the typo.
Most probably, here this is due to the symbol ˆ you are using, which is not the appropriate one for an exponent ^:
# correct symbol ^:
> 2^2
[1] 4
# wrong symbol you seem to use ˆ :
> 2ˆ2
Error: unexpected input in "2ˆ"
Change it to the correct one ^ and you will be fine.
I have a column of a few thousand prison facility names that have been scraped from the internet, some of which contain a "/" character. I'm running a ggplot loop that plots COVID infections in each facility, but the ggsave() function breaks whenever it hits a facility with the / because it thinks I am changing the file directory.
Is there a way to change the "/" character in my column to a "-"? I tried using gsub() but to no avail:
(1)
fix$Name <- gsub("\/"","-",gsub$Name)
I get the following error (2)
Error in gsub$Name : object of type 'closure' is not subsettable
I initially tried to just run (3)
fix$Name <- gsub("/","-",gsub$Name)
But I am fairly sure that I need an escape character, hence code line (1).
fix$Name is a character string.
If anyone has an insight that would be greatly appreciated! Thanks!
I'm trying to build an org chart from a data.frame in r using the data.tree package.
As far as i can tell i have constructed the tree correctly, but when I try to plot() the data.tree object (which print()s fine) I get an error:
abort(0) at jsStackTrace#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:5:22110
stackTrace#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:5:22258
abort#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:28:10656
nullFunc_iii#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:5:662065
a8#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:21:31634
iC#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:9:83383
aD#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:9:102098
uF#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:9:173805
pG#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:9:204484
xc#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:11:740
http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:28:403
ccallFunc#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:5:15982
http://localhost:30899/session/viewhtml2fdc215a4edd/lib/viz-0.3/viz.js:47:42
renderValue#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/grViz-binding-0.8.4/grViz.js:38:27
http://localhost:30899/session/viewhtml2fdc215a4edd/lib/htmlwidgets-0.7/htmlwidgets.js:625:30
forEach#[native code]
forEach#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/htmlwidgets-0.7/htmlwidgets.js:55:21
http://localhost:30899/session/viewhtml2fdc215a4edd/lib/htmlwidgets-0.7/htmlwidgets.js:551:14
forEach#[native code]
forEach#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/htmlwidgets-0.7/htmlwidgets.js:55:21
staticRender#http://localhost:30899/session/viewhtml2fdc215a4edd/lib/htmlwidgets-0.7/htmlwidgets.js:549:12
http://localhost:30899/session/viewhtml2fdc215a4edd/lib/htmlwidgets-0.7/htmlwidgets.js:638:38
Any ideas?
I have just started using the data.frame package a couple of days ago, but came across the same problem with some of my trees - print(tree) worked but plot(tree) gave a similar error message to yours. So far, I could always resolve the issue by removing special characters like single and double quotation marks from the input data. Thus, the plot function appears to be sensitive to certain symbols or special characters ... maybe a starting point for your search for a solution?
This is an example from the KFAS manual page 13. I just tried a copy/paste and this was the result. Any idea what the problem is?
There were additional errors with the rest of the example.
> require(KFAS)
Loading required package: KFAS
> data(GlobalTemp)
> model<-SSModel(GlobalTemp~SSMtrend(1,Q=NA,type= common ),H=matrix(NA,2,2))
Error in ts(x) : object is not a matrix
Did you copy the example by hand? The line in the manual (at least this one: http://cran.r-project.org/web/packages/KFAS/KFAS.pdf) uses this command:
require(KFAS)
data(GlobalTemp)
model<-SSModel(GlobalTemp~SSMtrend(1,Q=NA,type='common'),H=matrix(NA,2,2))
With the ' around common (and it works fs)
However you should have got the "common not found" error message, not the one you quote (except you already have an object named common in your environment), so I don't really know if this answer will help you.
I'm tryin to convert some common names to scientific names using taxize, but the functions are returning errors.
From the help page:
library(taxize)
comm2sci(commnames='black bear')
# Error: could not find function "comm2sci"
In addition, the sci2comm isn't working:
sci2comm(scinames='Helianthus annuus')
# Error: could not find function "sci2comm"
Ay reason they arent working? Any other way of getting scientific names in R?