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

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

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

                                        Count the Number of Characters (or Bytes or Width)
                                         计数的字符数(或字节或宽)

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

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

nchar takes a character vector as an argument and returns a vector whose elements contain the sizes of the corresponding elements of x.
nchar作为参数字符向量,并返回一个向量,其元素包含x相应的元素的大小。

nzchar is a fast way to find out if elements of a character vector are non-empty strings.
nzchar是一个快速的方式来找出一个特征向量的元素,如果非空字符串。


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


nchar(x, type = "chars", allowNA = FALSE)

nzchar(x)



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

参数:x
character vector, or a vector to be coerced to a character vector.
特征向量,向量被裹挟到一个字符向量。


参数:type
character string: partial matching to one of c("bytes", "chars", "width").  See "Details".
字符串:部分匹配c("bytes", "chars", "width")。见“详细资料”。


参数:allowNA
logical: should NA be returned for invalid multibyte strings or "bytes"-encoded strings (rather than throwing an error)?
逻辑:应NA返回无效的多字节字符串或"bytes"编码的字符串(而不是抛出一个错误)?


Details

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

The "size" of a character string can be measured in one of three ways
字符串的大小可以测量三种方式之一




bytes The number of bytes needed to store the string
bytes需要存储的字符串的字节数




chars The number of human-readable characters.
chars人类可读的字符数。




width The number of columns cat will use to print the string in a monospaced font.  The same as chars
width列cat将使用打印等宽字体的字符串。同样的chars

These will often be the same, and almost always will be in single-byte locales.  There will be differences between the first two with multibyte character sequences, e.g. in UTF-8 locales.
这些往往会是相同的,几乎总是会在单字节语言环境。前两个之间会有分歧与多字节字符序列,例如UTF-8语言环境。

The internal equivalent of the default method of as.character is performed on x (so there is no method dispatch).  If you want to operate on non-vector objects passing them through deparse first will be required.
默认的方法as.character内部等效x(这样有没有方法调度)。如果你要操作的对象通过他们通过对非向量deparse首先将需要。


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

For nchar, an integer vector giving the sizes of each element, currently always 2 for missing values (for NA).
nchar,整数向量给每个元素的大小,目前始终2遗漏值(NA)。

If allowNA = TRUE and an element is invalid in a multi-byte character set such as UTF-8, its number of characters and the width will be NA.  Otherwise the number of characters will be non-negative, so !is.na(nchar(x, "chars", TRUE)) is a test of validity.
如果allowNA = TRUE“元素是无效的,在一个多字节字符集如UTF-8,其字符的数量和宽度将是NA。否则的字符数将非负,所以!is.na(nchar(x, "chars", TRUE))是一个测试的有效性。

A character string marked with "bytes" encoding has a number of bytes, but neither a known number of characters nor a width, so the latter two types are NA if allowNA = TRUE, otherwise an error.
"bytes"编码标记的一个字符串的字节数,但既不是已知的字符数,也不是宽度,使后者的两种类型的NA如果allowNA = TRUE,否则错误。

Names, dims and dimnames are copied from the input.
名称,变暗和dimnames的从输入复制。

For nzchar, a logical vector of the same length as x, true if and only if the element has non-zero length.
nzchar,逻辑向量的长度相同x,真当且仅如果该元素具有非零长度。


注意----------Note----------

This does <STRONG>not</STRONG> by default give the number of characters that will be used to print() the string.  Use encodeString to find the characters used to print the string. This is particularly important on Windows when \uxxxx sequences have been used to enter Unicode characters not representable in the current encoding.  Thus nchar("\u2642") is 1, and it is printed in Rgui as one character, but it will be printed in Rterm as <U+2642>, which is what encodeString gives.
这确实<strong>不会</强>默认情况下,将用于print()字符串的字符数。使用encodeString找到用于打印字符串的字符。这是Windows上尤为重要,当\uxxxx序列已进入并不表示在当前编码的Unicode字符。因此nchar("\u2642")是1,Rgui作为一个字符,但它会被印在印Rterm<U+2642>,这是什么encodeString给。


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

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

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

strwidth giving width of strings for plotting; paste, substr, strsplit
strwidth给绘制的字符串的宽度;paste,substr,strsplit


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


x <- c("asfef", "qwerty", "yuiop[", "b", "stuff.blah.yech")
nchar(x)
# 5  6  6  1 15[5 6 6 1 15]

nchar(deparse(mean))
# 18 17[18 17]

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-23 09:26 , Processed in 0.029471 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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