Wrap first letter in data frame

Here are my details,

> data Manufacturers Models 1 audi RS5 2 bmw M3 3 cadillac CTS-V 4 lexus ISF 

And I would like to smooth out the first letter in the first column, for example:

 > data Manufacturers Models 1 audi RS5 2 bmw M3 3 cadillac CTS-V 4 lexus ISF 

I would be grateful for any help on this. Thank you very much.

+4
source share
2 answers

Taking an 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 
+8
source

Or, taking an example from ?gsub :

 data$Manufacturers <- gsub("^(\\w)(\\w+)", "\\U\\1\\L\\2", data$Manufacturers, perl = TRUE) > data > Manufacturers Models 1 Audi RS5 2 Bmw M3 3 Cadillac CTS-V 4 Lexus ISF 
+4
source

All Articles