- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to put space between words that start with uppercase letter in string vector in R?
To put space between words that start with uppercase letter in string vector in R, we can use gsub function. Since we can have uppercase letters as well as lowercase letters in the string vector hence, we need to properly specify both type of characters for creating the space between words. Check out the below examples to understand how it works.
Example
x1<-c("RIsAProgrammingLanguageAndSoftwareEnvironmentForStatisticalAnalysis,GraphicsRepresentationAndReporting.RWasCreatedByRossIhakaAndRobertGentlemanAtTheUniversityOfAuckland,NewZealand,AndIsCurrentlyDevelopedByTheRDevelopmentCoreTeam. RIsFreelyAvailableUnderTheGNUGeneralPublicLicense,AndPre-compiledBinaryVersionsAreProvidedForVariousOperatingSystemsLikeLinux,WindowsAndMac. ThisProgrammingLanguageWasNamedR,BasedOnTheFirstLetterOfFirstNameOfTheTwoRAuthors(RobertGentlemanAndRossIhaka),AndPartlyAPlayOnTheNameOfTheBellLabsLanguage S.") x1
Output
[1] "RIsAProgrammingLanguageAndSoftwareEnvironmentForStatisticalAnalysis,GraphicsRepresentationAndReporting.RWasCreatedByRossIhakaAndRobertGentlemanAtTheUniversityOfAuckland,NewZealand,AndIsCurrentlyDevelopedByTheRDevelopmentCoreTeam. RIsFreelyAvailableUnderTheGNUGeneralPublicLicense,AndPre-compiledBinaryVersionsAreProvidedForVariousOperatingSystemsLikeLinux,WindowsAndMac. ThisProgrammingLanguageWasNamedR,BasedOnTheFirstLetterOfFirstNameOfTheTwoRAuthors(RobertGentlemanAndRossIhaka),AndPartlyAPlayOnTheNameOfTheBellLabsLanguage S."
Example
gsub("([a-z])([A-Z])","\1 \2",x1)
Output
[1] "RIs AProgramming Language And Software Environment For Statistical Analysis,Graphics Representation And Reporting.RWas Created By Ross Ihaka And Robert Gentleman At The University Of Auckland,New Zealand,And Is Currently Developed By The RDevelopment Core Team. RIs Freely Available Under The GNUGeneral Public License,And Pre-compiled Binary Versions Are Provided For Various Operating Systems Like Linux,Windows And Mac. This Programming Language Was Named R,Based On The First Letter Of First Name Of The Two RAuthors(Robert Gentleman And Ross Ihaka),And Partly APlay On The Name Of The Bell Labs Language S."
Example
x2<-sample(c("TutorialspointIsAnElearningCompany","HereWeCanFindFreeTutorialsAndPaidCoursesAtMinimalPrices","TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers"),20,replace=TRUE) x2
Output
[1] "TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers" [2] "TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers" [3] "HereWeCanFindFreeTutorialsAndPaidCoursesAtMinimalPrices" [4] "TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers" [5] "TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers" [6] "TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers" [7] "TutorialspointIsAnElearningCompany" [8] "TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers" [9] "TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers" [10] "TutorialspointIsAnElearningCompany" [11] "TutorialspointIsAnElearningCompany" [12] "HereWeCanFindFreeTutorialsAndPaidCoursesAtMinimalPrices" [13] "TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers" [14] "TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers" [15] "TutorialspointIsAnElearningCompany" [16] "HereWeCanFindFreeTutorialsAndPaidCoursesAtMinimalPrices" [17] "HereWeCanFindFreeTutorialsAndPaidCoursesAtMinimalPrices" [18] "HereWeCanFindFreeTutorialsAndPaidCoursesAtMinimalPrices" [19] "TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers" [20] "TutorialspointAlsoOffersManyOtherThingsLikeQualityPdfsAndLiveCompilers"
Example
gsub("([a-z])([A-Z])","\1 \2",x2)
Output
[1] "Tutorialspoint Also Offers Many Other Things Like Quality Pdfs And Live Compilers" [2] "Tutorialspoint Also Offers Many Other Things Like Quality Pdfs And Live Compilers" [3] "Here We Can Find Free Tutorials And Paid Courses At Minimal Prices" [4] "Tutorialspoint Also Offers Many Other Things Like Quality Pdfs And Live Compilers" [5] "Tutorialspoint Also Offers Many Other Things Like Quality Pdfs And Live Compilers" [6] "Tutorialspoint Also Offers Many Other Things Like Quality Pdfs And Live Compilers" [7] "Tutorialspoint Is An Elearning Company" [8] "Tutorialspoint Also Offers Many Other Things Like Quality Pdfs And Live Compilers" [9] "Tutorialspoint Also Offers Many Other Things Like Quality Pdfs And Live Compilers" [10] "Tutorialspoint Is An Elearning Company" [11] "Tutorialspoint Is An Elearning Company" [12] "Here We Can Find Free Tutorials And Paid Courses At Minimal Prices" [13] "Tutorialspoint Also Offers Many Other Things Like Quality Pdfs And Live Compilers" [14] "Tutorialspoint Also Offers Many Other Things Like Quality Pdfs And Live Compilers" [15] "Tutorialspoint Is An Elearning Company" [16] "Here We Can Find Free Tutorials And Paid Courses At Minimal Prices" [17] "Here We Can Find Free Tutorials And Paid Courses At Minimal Prices" [18] "Here We Can Find Free Tutorials And Paid Courses At Minimal Prices" [19] "Tutorialspoint Also Offers Many Other Things Like Quality Pdfs And Live Compilers" [20] "Tutorialspoint Also Offers Many Other Things Like Quality Pdfs And Live Compilers"
- Related Articles
- How to extract words from a string vector in R?
- How to replace space between two words with underscore in an R data frame column?
- How to create a vector with lowercase as well as uppercase letters in R?
- Make first letter of a string uppercase in JavaScript?
- How to convert all words of a string or categorical variable in an R data frame to uppercase?
- How to lowercase the entire string keeping the first letter in uppercase with MySQL?\n\n\n
- How to find similar words in vector of strings in R?
- How to reduce the space between two plots that are joined with grid.arrange in R?
- First uppercase letter in a string (Iterative and Recursive) in C++
- Regex in Python to put spaces between words starting with capital letters
- How to test if a letter in a string is uppercase or lowercase using javascript?
- Remove space between two words in MySQL?
- How to convert a string vector into an integer vector in R?
- c# Put spaces between words starting with capital letters
- How to find all combinations of a vector elements without space in R?

Advertisements