Error: unexpected symbol when I am using ppDist

Hi, I am a new user of Rstudio. I am trying to calculate distance between points but when I am typing the command I get the following error:

Error: unexpected symbol in "ppDist <- function(pnt1, pnt2){dist <- sqrt((pnt2[1]-pnt1[1])^2 + (pnt2[2]-pnt1[2])^2)unlist"

The command that I give is the following:

ppDist <- function(pnt1, pnt2){dist <- sqrt((pnt2[1]-pnt1[1])^2 + (pnt2[2]-pnt1[2])^2)unlist(dist)}

Can you help me to solve it?
Thanks in advance

What is unlist(dist) doing for you?

Leaving aside the functionality of your code, you are getting that error message because you have a syntax error, unlist() shouldnt be on the same line inmediatly following a paranthesis, try this:

ppDist <- function(pnt1, pnt2) { 
    dist <- sqrt((pnt2[1]-pnt1[1])^2 + (pnt2[2]-pnt1[2])^2)
    unlist(dist)
}

Thanks andresrcs! I fixed it!

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.