0

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?

0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.