Labros
February 3, 2020, 9:28am
1
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)
}
Labros
February 3, 2020, 3:15pm
4
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:
If your question has been answered, don't forget to mark the solution!
How do I mark a solution?
Find the reply you want to mark as the solution and look for the row of small gray icons at the bottom of that reply. Click the one that looks like a box with a checkmark in it:
[image]
Hovering over the mark solution button shows the label, "Select if this reply solves the problem". If you don't see the mark solution button, try clicking the three dots button ( ••• ) to expand the full set of options.
When a solution is chosen, the icon turns green and the hover label changes to: "Unselect if this reply no longer solves the problem". Success!
[solution_reply_author]
…
system
Closed
February 24, 2020, 3:46pm
6
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.