找回密码
 注册
查看: 4055|回复: 0

R语言:format()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 18:26:32 | 显示全部楼层 |阅读模式
format(base)
format()所属R语言包:base

                                        Encode in a Common Format
                                         在一个共同的格式编码

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Format an R object for pretty printing.
格式化一个漂亮的印刷R对象。


用法----------Usage----------


format(x, ...)

## Default S3 method:[默认方法]
format(x, trim = FALSE, digits = NULL, nsmall = 0L,
       justify = c("left", "right", "centre", "none"),
       width = NULL, na.encode = TRUE, scientific = NA,
       big.mark = "",   big.interval = 3L,
       small.mark = "", small.interval = 5L,
       decimal.mark = ".", zero.print = NULL,
       drop0trailing = FALSE, ...)

## S3 method for class 'data.frame'
format(x, ..., justify = "none")

## S3 method for class 'factor'
format(x, ...)

## S3 method for class 'AsIs'
format(x, width = 12, ...)



参数----------Arguments----------

参数:x
any R object (conceptually); typically numeric.
任何R对象(概念);典型的数字。


参数:trim
logical; if FALSE, logical, numeric and complex values are right-justified to a common width: if TRUE the leading blanks for justification are suppressed.
逻辑;如果FALSE,逻辑,数字和复杂的值是右对齐到一个共同的宽度:如果TRUE为理由的前导空格被抑制。


参数:digits
how many significant digits are to be used for numeric and complex x.  The default, NULL, uses getOption(digits).  This is a suggestion: enough decimal places will be used so that the smallest (in magnitude) number has this many significant digits, and also to satisfy nsmall. (For the interpretation for complex numbers see signif.)
多少重大的数字是数字和复杂的x使用。默认情况下,NULL使用getOption(digits)。这是一个建议:将使用足够的小数点后最小(中量级)的数量有很多重要的数字,也满足nsmall。 (见复数的解释signif。)


参数:nsmall
the minimum number of digits to the right of the decimal point in formatting real/complex numbers in non-scientific formats. Allowed values are 0 <= nsmall <= 20.
在非科学的格式格式化的实数/复数小数点右边的数字的最小数目。允许的值是0 <= nsmall <= 20。


参数:justify
should a character vector be left-justified (the default), right-justified, centred or left alone.
字符向量应该是左对齐(默认),右对齐,居中或独处。


参数:width
default method: the minimum field width or NULL or 0 for no restriction.  AsIs method: the maximum field width for non-character objects.  NULL corresponds to the default 12.  
default方法:最小字段宽度或没有限制的NULL或0。 AsIs方法:非字符对象的最大字段宽度。 NULL对应的默认为12。


参数:na.encode
logical: should NA strings be encoded?  Note this only applies to elements of character vectors, not to numerical or logical NAs, which are always encoded as "NA".
逻辑:应NA字符串进行编码?请注意这仅适用于特征向量的元素,而不是数字或逻辑NAs,这总是"NA"的编码。


参数:scientific
Either a logical specifying whether elements of a real or complex vector should be encoded in scientific format, or an integer penalty (see options("scipen")). Missing values correspond to the current default penalty.
无论是逻辑指定一个真正的或复杂的矢量元素是否应在科学的格式,或一个整数的罚款编码(见options("scipen"))。遗漏值对应到目前的违约金。


参数:...
further arguments passed to or from other methods.
通过进一步的论据或其他方法。

used for prettying (longish) decimal sequences, passed to prettyNum: that help page explains the details.
用于十进制序列prettying(稍长),传递给prettyNum帮助页解释的细节。


Details

详情----------Details----------

format is a generic function.  Apart from the methods described here there are methods for dates (see format.Date), date-times (see format.POSIXct)) and for other classes such as format.octmode and format.dist.
format是一个通用的功能。除了这里描述的方法有日期的方法(见format.Date),日期时间(见format.POSIXct))和其他类,如format.octmode和format.dist。

format.data.frame formats the data frame column by column, applying the appropriate method of format for each column. Methods for columns are often similar to as.character but offer more control.  Matrix and data-frame columns will be converted to separate columns in the result, and character columns (normally all) will be given class "AsIs".
format.data.frame格式列数据的框架柱,采用适当的方法format每列。列的方法往往as.character类似,但提供了更多的控制。结果,矩阵和数据框的列将被转换为单独的列和字符列(通常)将给予类"AsIs"。

format.factor converts the factor to a character vector and then calls the default method (and so justify applies).
format.factor转换成一个字符向量的因素,然后调用默认方法(所以justify适用)。

format.AsIs deals with columns of complicated objects that have been extracted from a data frame.  Character objects are passed to the default method (and so width does not apply). Otherwise it calls toString to convert the object to character (if a vector or list, element by element) and then right-justifies the result.
format.AsIs处理复杂的对象已经从一个数据框中提取列。字符传递给对象的默认方法(width不适用)。否则,它调用toString对象转换为字符(如果一个向量或列表,通过元素的元素),然后右对齐结果。

Justification for character vectors (and objects converted to character vectors by their methods) is done on display width (see nchar), taking double-width characters and the rendering of special characters (as escape sequences, including escaping backslash but not double quote: see print.default) into account.  Thus the width is as displayed by print(quote =   FALSE) and not as displayed by cat.  Character strings are padded with blanks to the display width of the widest.  (If na.encode = FALSE missing character strings are not included in the width computations and are not encoded.)
特征向量(他们的方法和转换特征向量对象)的理由是显示宽度(见nchar),采取双宽字符和特殊字符的渲染(转义序列,包括转义的反斜线,但不双引号:考虑print.default)。因此,宽度显示print(quote =   FALSE)而不是cat显示。字符串填充到最广泛的显示宽度的空白。 (如果na.encode = FALSE缺少的字符串宽度计算,不包括未编码)。

Numeric vectors are encoded with the minimum number of decimal places needed to display all the elements to at least the digits significant digits.  However, if all the elements then have trailing zeroes, the number of decimal places is reduced until at least one element has a non-zero final digit; see also the argument documentation for big.*, small.* etc, above.  See the note in print.default about digits >= 16.
数字矢量进行编码,需要显示所有的元素至少digits有效位数小数的最低数量。然而,如果所有的元素,然后尾随零,小数位数减少,直到至少有一个元素有一个非零的最后一位,也看到的参数文件big.*,small.*等,以上。见print.defaultdigits >= 16说明。

Raw vectors are converted to their 2-digit hexadecimal representation by as.character.
as.character原始向量转换为2位十六进制表示。


值----------Value----------

An object of similar structure to x containing character representations of the elements of the first argument x in a common format, and in the current locale's encoding.
结构相似的对象x第一个参数中的元素包含字符表示x在一个共同的格式,并在当前的区域设置的编码。

For character, numeric, complex or factor x, dims and dimnames are preserved on matrices/arrays and names on vectors: no other attributes are copied.
对于字符,数字,复杂或因素x,变暗和dimnames的保留矩阵/阵列和向量名:没有其他的属性被复制。

If x is a list, the result is a character vector obtained by applying format.default(x, ...) to each element of the list (after unlisting elements which are themselves lists), and then collapsing the result for each element with paste(collapse = ", ").  The defaults in this case are trim = TRUE, justify = "none" since one does not usually want alignment in the collapsed strings.
如果x是一个列表,其结果是申请format.default(x, ...)列表中的每个元素(unlist自己列出的元素之后)得到的特征向量,然后崩溃的结果用paste(collapse = ", ")每个元素。在这种情况下,默认是trim = TRUE, justify = "none"因为人们通常不希望在倒塌的字符串对齐。


参考文献----------References----------

The New S Language. Wadsworth &amp; Brooks/Cole.

参见----------See Also----------

format.info indicates how an atomic vector would be formatted.
format.info表示原子向量将被格式化。

formatC, paste, as.character, sprintf, print, prettyNum, toString, encodeString.
formatC,paste,as.character,sprintf,print,prettyNum,toString,encodeString。


举例----------Examples----------


format(1:10)
format(1:10, trim = TRUE)

zz <- data.frame("(row names)"= c("aaaaa", "b"), check.names=FALSE)
format(zz)
format(zz, justify = "left")

## use of nsmall[#的nsmall使用]
format(13.7)
format(13.7, nsmall = 3)
format(c(6.0, 13.1), digits = 2)
format(c(6.0, 13.1), digits = 2, nsmall = 1)

## use of scientific[#使用的科学]
format(2^31-1)
format(2^31-1, scientific = TRUE)

## a list[#列表]
z <- list(a=letters[1:3], b=(-pi+0i)^((-2:2)/2), c=c(1,10,100,1000),
          d=c("a", "longer", "character", "string"))
format(z, digits = 2)
format(z, digits = 2, justify = "left", trim = FALSE)

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-23 21:15 , Processed in 0.023556 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表