【发布时间】:2019-11-02 16:16:26
【问题描述】:
我是任何类型的编程的新学生,并且无法在 R 中创建一个计算斜率的函数。这些错误意味着什么会阻止函数工作?
slope <- function(x1,y1,x2,y2) {
missingvars=c(missing(x1),missing(y1),missing(x2),missing(y2))
if(sum(missingvars)>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)
}
Error: unexpected '}' in "}"
> slope <- function(x1,y1,x2,y2) {
+
+ missingvars=c(missing(x1),missing(y1),missing(x2),missing(y2))
+
+ if(sum(missingvars)>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)>0){
stop(paste(�"
> Y2 -“,missingvars[4],sep=“”))
Error: unexpected input in "Y2 -�"
> }
Error: unexpected '}' in "}"
【问题讨论】: