title: Creating a function to calculate slope m=(y2-y1)/(x2-x1) in R
body: <p>I am a new student to programming of any kind and am having trouble creating a function to calculate slope in R.  What do these errors mean that are preventing the function from working?</p>
  
  <pre><code>slope &lt;- function(x1,y1,x2,y2) {
  
  missingvars=c(missing(x1),missing(y1),missing(x2),missing(y2))
  
  if(sum(missingvars)&gt;0){
  stop(paste(“Values were not provided (denoted by TRUE): x1 -”,missingvars[1],“, y1 -”,missingvars[2],“, x2 -”,missingvars[3],“, 
  Y2 -”,missingvars[4],sep=“”))
  }
  
  if(x2-x1==0) {
  stop(“Both X values are the same, slope cannot be calculated when X are the same.”)
  }
  
  m = (y2-y1)/(x2-x1)
  return(m)
  
  }
  </code></pre>
  
  <pre><code>Error: unexpected '}' in "}"
  &gt; slope &lt;- function(x1,y1,x2,y2) {
  + 
  + missingvars=c(missing(x1),missing(y1),missing(x2),missing(y2))
  + 
  + if(sum(missingvars)&gt;0){
  + stop(paste(“Values were not provided (denoted by TRUE): x1 -“,missingvars[1],”, y1 -“,missingvars[2],”, x2 -“,missingvars[3],”, 
  Error: unexpected input in:
  "if(sum(missingvars)&gt;0){
  stop(paste(�"
  &gt; Y2 -“,missingvars[4],sep=“”))
  Error: unexpected input in "Y2 -�"
  &gt; }
  Error: unexpected '}' in "}"
  </code></pre>