查看R源代码的六种方法

> methods(length)
[1] length.pdf_doc* length.POSIXlt 
see '?methods' for accessing help and source code
> length.POSIXlt
function (x) 
length(x[[1L]])
<bytecode: 0x00000000111d75b0>
<environment: namespace:base>
 

-------------------------------------------------------------------------

 

 

方法一:直接写函数名称,如在R中查看回归分析代码:

  1. lm

复制代码


直接可以查看到

  1. function (formula, data, subset, weights, na.action, method = "qr", 
  2.     model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, 
  3.     contrasts = NULL, offset, ...) 
  4. {
  5.     ret.x <- x
  6.     ret.y <- y
  7.     cl <- match.call()
  8.     mf <- match.call(expand.dots = FALSE)
  9.     m <- match(c("formula", "data", "subset", "weights", "na.action", 
  10.         "offset"), names(mf), 0L)
  11.     mf <- mf[c(1L, m)]
  12.     mf$drop.unused.levels <- TRUE
  13.     mf[[1L]] <- quote(stats::model.frame)
  14.     mf <- eval(mf, parent.frame())
  15.     if (method == "model.frame") 
  16.         return(mf)
  17.     else if (method != "qr") 
  18.         warning(gettextf("method = '%s' is not supported. Using 'qr'", 
  19.             method), domain = NA)
  20.     mt <- attr(mf, "terms")
  21.     y <- model.response(mf, "numeric")
  22.     w <- as.vector(model.weights(mf))
  23.     if (!is.null(w) && !is.numeric(w)) 
  24.     
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值