substr(base)
substr()所属R语言包:base
Substrings of a Character Vector
子串的字符向量
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Extract or replace substrings in a character vector.
提取或替换字符向量的子串。
用法----------Usage----------
substr(x, start, stop)
substring(text, first, last = 1000000L)
substr(x, start, stop) <- value
substring(text, first, last = 1000000L) <- value
参数----------Arguments----------
参数:x, text
a character vector.
字符向量。
参数:start, first
integer. The first element to be replaced.
整数。第一个元素被替换。
参数:stop, last
integer. The last element to be replaced.
整数。最后一个元素被替换。
参数:value
a character vector, recycled if necessary.
字符向量,如果有必要回收。
Details
详情----------Details----------
substring is compatible with S, with first and last instead of start and stop. For vector arguments, it expands the arguments cyclically to the length of the longest provided none are of zero length.
substring是用S兼容,first和last代替start和stop。矢量参数,它扩大了循环参数的长度最长没有长度为零。
When extracting, if start is larger than the string length then "" is returned.
提取时,start如果大于字符串的长度,那么""返回。
For the extraction functions, x or text will be converted to a character vector by as.character if it is not already one.
提取功能,x或textas.character将被转换到一个字符向量“,如果它是没有一个。
For the replacement functions, if start is larger than the string length then no replacement is done. If the portion to be replaced is longer than the replacement string, then only the portion the length of the string is replaced.
更换功能,start如果是大于字符串的长度则没有更换完成。如果被替换的部分是比替换字符串长,那么只有部分被替换的字符串的长度。
If any argument is an NA element, the corresponding element of the answer is NA.
如果任何参数是一个NA元素,相应的元素的答案是NA。
Elements of the result will be have the encoding declared as that of the current locale (see Encoding if the corresponding input had a declared Latin-1 or UTF-8 encoding and the current locale is either Latin-1 or UTF-8.
元素的结果将有编码声明作为当前区域(见Encoding相应的输入,如果有一个宣布的Latin-1或UTF-8编码和当前的语言环境是为Latin-1或UTF- 8。
If an input element has declared "bytes" encoding, the subsetting is done in units of bytes not characters.
如果输入元素已宣布"bytes"编码,子集不是字符的字节为单位进行。
值----------Value----------
For substr, a character vector of the same length and with the same attributes as x (after possible coercion).
substr,x(后可能强制)相同的属性相同的长度和特征向量。
For substring, a character vector of length the longest of the arguments. This will have names taken from x (if it has any after coercion, repeated as needed), and other attributes copied from x if it is the longest of the arguments).
对于substring,长度为特征向量最长的论点。这将有名字取自x(如果有任何胁迫后,重复如需要),并从x复制其他属性,如果它是最长的参数)。
Elements of x with a declared encoding (see Encoding) will be returned with the same encoding.
元素x宣告的编码(Encoding)将返回相同的编码。
注意----------Note----------
The S4 version of substring<- ignores last; this version does not.
S4版本的substring<-忽略last;这个版本不。
These functions are often used with nchar to truncate a display. That does not really work (you want to limit the width, not the number of characters, so it would be better to use strtrim), but at least make sure you use the default nchar(type="c").
这些功能经常被用来与nchar截断显示。并没有真正的工作(你想要的宽度,而不是字符数限制,所以它会更好地使用strtrim),但至少确保你使用默认的nchar(type="c")。
参考文献----------References----------
The New S Language. Wadsworth & Brooks/Cole. (<code>substring</code>.)
参见----------See Also----------
strsplit, paste, nchar.
strsplit,paste,nchar。
举例----------Examples----------
substr("abcdef",2,4)
substring("abcdef",1:6,1:6)
## strsplit is more efficient ...[#strsplit是更有效...]
substr(rep("abcdef",4),1:4,4:5)
x <- c("asfef", "qwerty", "yuiop[", "b", "stuff.blah.yech")
substr(x, 2, 5)
substring(x, 2, 4:6)
substring(x, 2) <- c("..", "+++")
x
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|