尝试对数组执行导数,这是我生成的代码:
x <- c(30, 50, 60, 70, 80, 85, 87, 88, 90, 91, 91.5, 91.8)
Der <- function(x) {
z <- array()
i <- 1
x <- c(NA, x)
for (i in length(x)) {
d<- x[i+1] - x[i]
z[i] <- d
i <- i +1
}
x <- z[2:length(z)]
return(x)
}
y <- Der(x)
有人可以告诉我我要去哪里错吗?
干杯