
r语言里new这个是什么意思
1个回答
展开全部
r语言里new 是函数,参数是methods, 原型是: new(methods)。
它可用来 生成 一个 类(class) 的 对象。
methods 提供class的名字,或 class 的定义,对象的具体参数数据等。
函数 返回对象的名字。
例如:
t1 <- new("track", x = seq_along(ydata), y = ydata)
t2 <- new("trackCurve", t1, smooth = ysmooth)
setMethod("initialize",
"track",
function(.Object, x = numeric(0), y = numeric(0)) {
if(nargs() > 1) {
if(length(x) != length(y))
stop("specified x and y of different lengths")
.Object@x <- x
.Object@y <- y
}
.Object
})
它可用来 生成 一个 类(class) 的 对象。
methods 提供class的名字,或 class 的定义,对象的具体参数数据等。
函数 返回对象的名字。
例如:
t1 <- new("track", x = seq_along(ydata), y = ydata)
t2 <- new("trackCurve", t1, smooth = ysmooth)
setMethod("initialize",
"track",
function(.Object, x = numeric(0), y = numeric(0)) {
if(nargs() > 1) {
if(length(x) != length(y))
stop("specified x and y of different lengths")
.Object@x <- x
.Object@y <- y
}
.Object
})
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |