大写字母数据帧中的第一个字母 [英] Uppercase the first letter in data frame
本文介绍了大写字母数据帧中的第一个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的资料
>数据
pre>
制造商型号
1 audi RS5
2 bmw M3
3 cadillac CTS-V
4 lexus ISF
我想在第一列中大写第一个字母,如下所示:
>数据
pre>
制造商型号
1奥迪RS5
2 Bmw M3
3凯迪拉克CTS-V
4雷克萨斯ISF
我希望有关于这个问题的任何帮助。非常感谢。
解决方案以
?toupper
并修改一下:capFirst< - 函数{
paste(toupper(substring s,1,1)),子串(s,2),sep =)
}
data $制造商< - capFirst(data $ Manufacturers)
> ;数据
#制造商型号
#1奥迪RS5
#2 Bmw M3
#3凯迪拉克CTS-V
#4雷克萨斯ISF
Heres my data,
> data Manufacturers Models 1 audi RS5 2 bmw M3 3 cadillac CTS-V 4 lexus ISF
And I would want to uppercase the first letter in the first column, like this:
> data Manufacturers Models 1 Audi RS5 2 Bmw M3 3 Cadillac CTS-V 4 Lexus ISF
I would appreciate any help on this question. Thanks a lot.
解决方案Taking the example from the documentation for
?toupper
and modifying it a bit:capFirst <- function(s) { paste(toupper(substring(s, 1, 1)), substring(s, 2), sep = "") } data$Manufacturers <- capFirst(data$Manufacturers) > data # Manufacturers Models # 1 Audi RS5 # 2 Bmw M3 # 3 Cadillac CTS-V # 4 Lexus ISF
这篇关于大写字母数据帧中的第一个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文