全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
3724 6
2007-01-21

比如在splus6.2发现找到的函数colMeans源代码如下 输入:colMeans 回车得到:function(x, na.rm = F, dims = 1)
{
if(is.data.frame(x))
...................... ......}
answer
}

在7.0试用版 输入:colMeans 回车得到:

function(x, ...)
.Call("S_c_use_method", "colMeans")

没有显示相应的源代码,

而在7.0中colMeans函数已作了修改,

现在我想把splus6.2中的colMeans函数源代码修改为7.0中colMeans函数定义。

没有源代码怎么办呢


[此贴子已经被作者于2007-1-21 19:42:57编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2007-1-21 21:03:00

7.0中的S语言函数用类对象封装

7.0中可以查看源代码

> colMeans
function(x, ...)
.Call("S_c_use_method", "colMeans")
> colMeans.default
function(x, na.rm = F, dims = 1, weights = NULL, freq = NULL, n = NULL
)
{
# Compute column means for a matrix.
# Supports higher-dimensional arrays - use dims to specify how
# many "row dimensions".
# May supply weights or frequencies (repetition counts).
# If `n' supplied, use that as number of rows, and
# and return vector w/o names.
# Otherwise return vector with names in usual case,
# or array with dimnames if there are at least 2 column dimensio
ns.
haveN <- !is.null(n)
if(haveN)
p <- length(x)/n
else {
if(length(dim(x)) < 2)
x <- as.matrix(x)
dimx <- dim(x)
if(dims < 1 || dims > length(dimx) - 1)
stop("dims not compatible with dim(x)")
dims <- seq(length = dims)
n <- prod(dimx[dims])
p <- prod(dimx[ - dims])
}
if(length(freq)) {
if(length(freq) != n)
stop("Length of freq does not match the number o
f rows"
)
if(length(weights))
weights <- weights * freq
else weights <- freq
}
answerIsNA <- F
if(length(weights)) {
# if weights supplied
if(length(weights) != n) stop(
"Length of weights does not match the nu
mber of rows"
)
# When calling C code, weights must have length 0 or n.
if(anyMissing(weights)) {
if(na.rm) {
wna <- which.na(weights)
weights <- weights[ - wna, drop = F]
dim(x) <- c(n, p)
x <- x[ - wna, , drop = F]
n <- nrow(x)
}
else answerIsNA <- T
}
}
if(answerIsNA)
answer <- NA * double(p)
else if(is.complex(x)) {
answer <- .C("S_colSums_NA_weights",
as.integer(n),
as.integer(p),
Re(x),
as.integer(length(weights)),
as.double(weights),
answer = double(p),
divide = TRUE,
as.integer(na.rm),
NAOK = T,
specialsok = T)$answer + (1i) * .C(
"S_colSums_NA_weights",
as.integer(n),
as.integer(p),
Im(x),
as.integer(length(weights)),
as.double(weights),
answer = double(p),
divide = TRUE,
as.integer(na.rm),
NAOK = T,
specialsok = T)$answer
}
else {
answer <- .C("S_colSums_NA_weights",
as.integer(n),
as.integer(p),
as.double(x),
as.integer(length(weights)),
as.double(weights),
answer = double(p),
divide = TRUE,
as.integer(na.rm),
NAOK = T,
specialsok = T)$answer
}
if(haveN)
return(answer)
if(length(dimx[ - dims]) > 1) {
#result is an array
dim(answer) <- dimx[ - dims]
if(!is.null(dimnames(x)))
dimnames(answer) <- dimnames(x)[ - dims]
}
else {
#result is a vector
temp <- dimnames(x)[[length(dimx)]]
if(length(temp) == p)
names(answer) <- temp
}
answer
}
ps:介绍s programming一书看看

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2007-1-21 21:05:00

还是自己试着多写点code

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2007-1-21 21:19:00

谢谢 你


谢谢 你

谢谢 你

[此贴子已经被作者于2007-1-21 22:41:03编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2007-1-22 08:21:00
不客气,多来光顾
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2008-11-6 16:22:00
xiexie
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群