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

Cleaning up the colors

Clean up the colors a little more by capitalizing all of the colors and inserting a delimiter:

col <- topper(paste0(col2, collapse = "|"))

Now pass the results to gsub():

cat("Pass to gsub\n", head(col, 9)) 
> Pass to gsub >  WHITE||AZURE|BEIGE|BISQUE|BLACK|BLUE|BROWN|CORAL|CYAN|DARKRED|DIMGRAY|GOLD|GRAY|GREEN|HOTPINK|IVORY|KHAKI|LINEN|MAGENTA|MAROON|NAVY|OLDLACE|ORANGE|ORCHID|PERU|PINK|PLUM|PURPLE|RED|SALMON|SIENNA|SKYBLUE|SNOW|TAN|THISTLE|TOMATO|VIOLET|WHEAT|YELLOW 

For example, to replace the colors in the dataframe with blanks:

OnlineRetail$Description <- gsub(col, "", OnlineRetail$Description)

Check the length to see how much was removed. As before, print the character count before and after, to ensure that ...

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