<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/character-functions-advanced/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-exercises.com/2017/05/18/character-functions-advanced/?utm_source=rss&utm_medium=rss&utm_campaign=character-functions-advanced"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/www.r-exercises.com/wp-content/uploads/2017/04/string.png"><img sizes="(max-width: 150px) 100vw, 150px" alt="" class="wp-image-5396" src="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2017/04/string-150x150.png?resize=150%2C150" data-recalc-dims="1"></a>This set of exercises will help you to help you improve your skills with character functions in R. Most of the exercises are related with text mining, a statistical technique that analyses text using statistics. If you find them interesting I would suggest checking the library <code>tm</code>, this includes functions designed for this task. There are many applications of text mining, a pretty popular one is the ability to associate a text with his or her author, this was how J.K.Rowling (Harry potter author) was caught publishing a new novel series under an alias. Before proceeding, it might be helpful to look over the help pages for the <code>nchar</code>, <code>tolower</code>, <code>toupper</code>, <code>grep</code>, <code>sub </code> and <code>strsplit</code>. Take at the library <code>stringr</code> and the functions it includes such as <code>str_sub</code>.</p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://r-exercises.com/2017/05/18/character-functions-advanced-solutions/">here.</a></p>
<p>If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.</p>
<p>Before starting the set of exercises run the following code lines :</p>
<p><code>if (!'tm' %in% installed.packages()) install.packages('tm')<br>
library(tm)<br>
txt = system.file(&quot;texts&quot;, &quot;txt&quot;, package = &quot;tm&quot;)<br>
ovid = VCorpus(DirSource(txt, encoding = &quot;UTF-8&quot;),<br>
readerControl = list(language = &quot;lat&quot;))<br>
OVID = c(data.frame(text=unlist(TEXT), stringsAsFactors = F))<br>
TEXT = lapply(ovid[1:5], as.character)<br>
TEXT1 = TEXT[[4]]<br>
</code></p>
<p><strong>Exercise 1</strong></p>
<p>Delete all the punctuation marks from TEXT1</p>
<p><strong>Exercise 2</strong></p>
<p>How many letters does TEXT1 contains?</p>
<p><strong>Exercise 3</strong></p>
<p>How many words does TEXT1 contains?</p>
<p><strong>Exercise 4</strong></p>
<p>What is the most common word in TEXT1?</p>
<div>
<aside><img src="http://www.r-exercises.com/2017/05/18/character-functions-advanced/?utm_source=rss&utm_medium=rss&utm_campaign=character-functions-advanced"></aside>
<div><strong>Learn more</strong> about Text analysis in the online course <a target="_blank" rel="nofollow" href="http://www.r-exercises.com/product/text-analyticstext-mining-using-r/">Text Analytics/Text Mining Using R</a>. In this course you will learn how create, analyse and finally visualize your text based data source. Having all the steps easily outlined will be a great reference source for future work.</div>
</div>
<p><strong>Exercise 5</strong></p>
<p>Get an object that contains all the words with at least one capital letter (Make sure the object contains each word only once)</p>
<p><strong>Exercise 6</strong></p>
<p>Which are the 5 most common letter in the object <code>OVID</code>?</p>
<p><strong>Exercise 7</strong></p>
<p>Which letters from the alphabet are not in the object <code>OVID</code></p>
<p><strong>Exercise 8</strong></p>
<p>On the <code>OVID</code> object, there is a character from the popular sitcom ‘FRIENDS’ , Who is he/she?  There were six main characters (Chandler, Phoebe, Ross, Monica, Joey, Rachel)</p>
<p><strong>Exercise 9</strong></p>
<p>Find the line where this character is mentioned</p>
<p><strong>Exercise 10</strong></p>
<p>How many words finish with a vowel, how many with a consonant?</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a title="Regular Expressions Exercises – Part 1" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2016/10/30/regular-expressions-part-1/">Regular Expressions Exercises – Part 1 </a></li>
<li><a title="Scan exercises" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2016/01/11/scan-exercises/">Scan exercises </a></li>
<li><a title="Building Shiny App exercises part 4" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2017/01/01/building-shiny-app-exercises-part-4/">Building Shiny App exercises part 4 </a></li>
<li><a target="_blank" rel="nofollow" href="http://www.r-exercises.com/start-here-to-learn-r/">Explore all our (>1000) R exercises</a></li>
<li><a target="_blank" rel="nofollow" href="http://www.r-exercises.com/r-courses/">Find an R course using our R Course Finder</a> directory</li>
</ol>
</div>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.r-exercises.com/2017/05/18/character-functions-advanced/?utm_source=rss&utm_medium=rss&utm_campaign=character-functions-advanced"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/EwjvSKwkjQM"></a></div>