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?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
mazuka487
  • 47
  • 9

1 Answers1

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.

desertnaut
  • 57,590
  • 26
  • 140
  • 166