【每天一个R语言命令】-toupper/tolower

【描述】

Translate characters in character vectors, in particular from upper to lower case or vice versa.
将字符转化为大写形式

【用法】

chartr(old, new, x)
tolower(x)
toupper(x)
casefold(x, upper = FALSE)

【参数】

a character vector, or an object that can be coerced to character by as.character.

old 
a character string specifying the characters to be translated. If a character vector of length 2 or more is supplied, the first element is used with a warning.

new 
a character string specifying the translations. If a character vector of length 2 or more is supplied, the first element is used with a warning.

upper   
logical: translate to upper or lower case?.

【代码】

> x <- "MiXeD cAsE 123"
> x
[1] "MiXeD cAsE 123"
> class(x)
[1] "character"
> chartr("iXs", "why", x)
[1] "MwheD cAyE 123" #把i转为w,X转为h,s转为y
> tolower(x)
[1] "mixed case 123"
> toupper(x)
[1] "MIXED CASE 123"
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容