加入收藏
大学数学, 研究生数学,大学数学资料下载,免费 大学数学课件,研究生数学课件,免费下载
R语言- length() 函数 (中文帮助)
2015-12-22 21:42:01

length {base}

[转载请注明出处,胡桃木屋 mathapply.cn ”R语言中文帮助“工作室译]


Length of an Object

对象的长度


Description(描述)

    Get or set the length of vectors (including lists) and factors, and of any other R object for which a method has been defined.

    获取或设置向量和因子的长度(包括列表lists),任何其它R对象都定义了该方法。


Usage(用法)
length(x)                    
length(x) <- value

Arguments
x    

     an R object. For replacement, a vector or factor.
     一个R对象。可用一个向量或因子替换。


value(返回值)
     a non-negative integer or double (which will be rounded down).

    一个非负整数或双精度(它可能会被保留整数)


Details(详细说明)
     Both functions are generic: you can write methods to handle specific classes of objects, see InternalMethods. length<- has a "factor" method.
     两个函数都是泛型函数,你可以写处理特殊对象类的该方法。见InternalMethods. length<-  有一个"因子" 方法.

     The replacement form can be used to reset the length of a vector. If a vector is shortened, extra values are discarded and when a vector is lengthened, it is padded out to its new length with NAs (nul for raw vectors).
    替换形式可以用于重新设置向量的长度。如果一个向量被缩短,额外的值被丢弃。 当一个向量被加长,则会使用NA填充到它的新长度。(raw向量使用nul填充)

    Both are primitive functions.
    两个都是原始函数。



Value(返回值)

    The default method for length currently returns a non-negative integer of length 1, except for vectors of more than 2^31 - 1 elements, when it returns a double.
     当前 length函数默认方法 返回一个长度为1的非负整数。如果是长度超过2^31 - 1个元素的向量,它会返回一个双精度。

    For vectors (including lists) and factors the length is the number of elements. For an environment it is the number of objects in the environment, and NULL has length 0. For expressions and pairlists (including language objects and dotlists) it is the length of the pairlist chain. All other objects (including functions) have length one: note that for functions this differs from S.
    向量(包括lists)和因子的长度是元素的数量,对于环境来说,它是环境中对象的数量。NULL的长度为0。表达式和配对列表(包括语言对象和点列表) 的长度是配对列表链的长度。所有其它对象(包括函数)有长度为1,注意函数的长度与S中不一样。

    The replacement form removes all the attributes of x except its names, which are adjusted (and if necessary extended by "").
    替换形式的函数会删除x中除了命名的的所有属性,命名属性可能会被调整(如果必要会通过“”扩展)。


Warning(警告)

    Package authors have written methods that return a result of length other than one (Formula) and that return a vector of type double (Matrix), even with non-integer values (earlier versions of sets). Where a single double value is returned that can be represented as an integer it is returned as a length-one integer vector.

    

    As from R 3.0.0, lengths can be returned as double in base R.



References (参考文献)


Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.



See Also (另见)
    nchar for counting the number of characters in character vectors, lengths for getting the length of every element in a list.
Examples (示例)
length(diag(4))  # = 16 (4 x 4)
length(options())  # 12 or more
length(y ~ x1 + x2 + x3)  # 3
length(expression(x, {y <- x^2; y+2}, x^y))  # 3

## from example(warpbreaks)
require(stats)

fm1 <- lm(breaks ~ wool * tension, data = warpbreaks)
length(fm1$call)      # 3, lm() and two arguments.
length(formula(fm1))  # 3, ~ lhs rhs

[Package base version 3.2.2 Index]
赞一个(123) | 阅读(13134)
上一篇:R语言- Multinom 分布(中文帮助)
下一篇:R语言- Logic () 函数 (中文帮助)
 

胡桃木屋版权所有@2013 湘ICP备13006789号-1