【发布时间】:2017-04-03 06:50:11
【问题描述】:
我需要将某些单词转换为小写。我正在处理一个电影标题列表,如果介词和冠词不是标题中的第一个单词,它们通常是小写的。如果我有向量:
movies = c('The Kings Of Summer', 'The Words', 'Out Of The Furnace', 'Me And Earl And The Dying Girl')
我需要的是这个:
movies_updated = c('The Kings of Summer', 'The Words', 'Out of the Furnace', 'Me and Earl and the Dying Girl')
有没有一种优雅的方式来做到这一点,而无需使用一长串的gsub(),如:
movies_updated = gsub(' In ', ' in ', movies)
movies_updated = gsub(' In', ' in', movies_updated)
movies_updated = gsub(' Of ', ' of ', movies)
movies_updated = gsub(' Of', ' of', movies_updated)
movies_updated = gsub(' The ', ' the ', movies)
movies_updated = gsub(' the', ' the', movies_updated)
等等。
【问题讨论】: