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

2021-01-30  本文已影响0人  肖ano

【描述】

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"
上一篇下一篇

猜你喜欢

热点阅读