O'Reilly logo

Practical Predictive Analytics by Ralph Winters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Custom function to map to camelcase

This is a simple example use of this function that maps the two character vector c("A certain good book", "A very easy book") to camelcase. This vector is mapped to two new elements:

[1] "ACertainGoodBook", and  [2] "AVeryEasyBook" 
 
# change descriptions to camelcase maybe append to itemnumber for uniqueness.simpleCap <- function(x) {    # s <- strsplit(x, ' ')[[1]]    s <- strsplit(tolower(x), " ")[[1]]     aa <- paste(toupper(substring(s, 1, 1)), substring(s, 2), sep = "", collapse = " ")    gsub(" ", "", aa, fixed = TRUE)}  
a  <- c("A certain good book", "A very easy book")a4 <- gsub(" ", "", .simpleCap(a), fixed = TRUE)a4 
> [1] "ACertainGoodBook" 
lapply(a, .simpleCap) 
> [[1]]> [1] "ACertainGoodBook"> > [[2]]> [1] "AVeryEasyBook" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required