R 关于大小写的转化

普通的大小写转换

将所有的大写转换成小写,将所有的小写转化成大写

#可以使用toupper()或者tolower()函数进行转化,我一般用于人与小鼠的同源基因的转化,当然这种转化是一非常粗暴的转化。
> head(c$SYMBOL)
[1] "Abca1"  "Abca4"  "Abca7"  "Abca13" "Abca12" "Abca2" 
> toupper(c$SYMBOL)
   [1] "ABCA1"         "ABCA4"         "ABCA7"         "ABCA13"       
   [5] "ABCA12"        "ABCA2"         
> tolower(toupper(c$SYMBOL))
   [1] "abca1"         "abca4"         "abca7"         "abca13"       
   [5] "abca12"        "abca2" 

我们希望首字母大写

可以使用stringr包中的str_to_title()函数

#每个单词的首字母都大写
> head(Hallmark_category$Process.category)
[1] "cellular component" "cellular component" "cellular component"
[4] "development"        "development"        "development"       
> str_to_title(head(Hallmark_category$Process.category))
[1] "Cellular Component" "Cellular Component" "Cellular Component"
[4] "Development"        "Development"        "Development"    
#当我们希望只有第一单词的首字母大写呢?可以利用str_to_sentence()这个函数轻松实现
> str_to_sentence(head(Hallmark_category$Process.category))
[1] "Cellular component" "Cellular component" "Cellular component"
[4] "Development"        "Development"        "Development"   

你可能感兴趣的:(r语言)