美文网首页
【每天一个R语言命令】-toupper/tolower

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

作者: 肖ano | 来源:发表于2021-01-30 10:26 被阅读0次

    【描述】

    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"
    

    相关文章

      网友评论

          本文标题:【每天一个R语言命令】-toupper/tolower

          本文链接:https://www.haomeiwen.com/subject/rpmhtltx.html