EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

R String Functions

By Anandkumar MurugesanAnandkumar Murugesan

Home » Data Science » Data Science Tutorials » R Programming Tutorial » R String Functions

R string Function

Introduction to R String Functions

R language or R String Functions is majorly implied for graphical representation of the data, statistical analysis on the data, and reporting. it is an open-source language. the naming convention of this language was derived from the first letters of the founders of this language they are Ross Ihaka and Robert Gentleman. It is an interpreted programming language. It has the ability to integrate with various other language procedures namely C++, Python, etc. Currently, R stands to be the world’s most largely used programming language.

Features of R String Functions

The key features of R language are as below,

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

  • A finely developed and very simple statistical language.
  • Storage and data handling are very efficiently embedded in R.
  • It offers a large set of classified tools which helps in data analysis
  • R also offers libraries to attain graphical representations of the data

R String Functions Manipulation

Below given is the list of R string manipulation functions.

1. Grep() in R String Functions

Used to match a pattern in the data and replace the pattern with a different string. The grep function can be expressed in multiple ways in R language’s are regexpr, gregexpr grep, grepl, and regexec.

Ex : grep( pattern, x, ignore. Case = FALSE, perl = FALSE, value = FALSE, fixed = FALSE, use Bytes = FALSE, invert = FALSE)

Arguments:

  • Pattern – Character string holding a usual expression that is supposed to equal the given character vector.
  • X, Text – An object which can be limited as a character to a character vector.
  • Ignore. Case – (False – Pattern matching works case insensitive, True – Pattern matching works case sensitive)
  • Perl – To determine Perl-compatible expressions especially regexprns be used.
  • Value – If a match found returns true else false,
  • Use Bytes – If TRUE after that the matching will be done byte-by-byte instead of character-by-character.
  • Invert – Returns indices if True,
  • Replacement – The replacement string,

2. Nchar()

Used to count the number of characters in a vector. Takes a vector in string format as an argument and returns another numeric vector that holds the count of the string.

Ex : nchar( x, type = “chars”, allowNA = FALSE, keepNA = NA)

Popular Course in this category
R Programming Training (12 Courses, 20+ Projects)12 Online Courses | 20 Hands-on Projects | 116+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,998 ratings)
Course Price

View Course

Related Courses
Statistical Analysis Training (10 Courses, 5+ Projects)All in One Data Science Bundle (360+ Courses, 50+ projects)

Arguments:

  • X – Vector string.
  • Type – Type, of the character string, used the three common ones mentioned are (“bytes”, “chars”, “width”).
  • AllowNA – Represents whether the ‘Not applicable’ can be returned as output.
  • KeepNA – Should ‘Not applicable’ be returned when X is not found.

3. Substr()

Used to pick the substring value of the character vector.

Ex : substr(x, start, stop)

Arguments:

  • X, text – The vector charterer string.
  • Start, First – integer. Start of the element which is expected to be replaced
  • Stop, Last – integer. here replacement is done at the end of the string

4. strsplit() in R String Functions

Used to split an existing vector string into multiple substrings according to the substring matches found within them

Ex : strsplit(x, split, fixed = FALSE, perl = FALSE, useBytes = FALSE)

Arguments:

  • X – Character vector which is going to be spited.
  • Split – Character vector which acts as the separator.
  • Fixed – Makes an equal split when it is passed as true
  • Perl – Should Perl-compatible regexps be used?
  • UseBytes – When passed as true it triggers byte by byte matching instead of character by character matching

5. Regexpr()

More than grep the regexpr gives the index where a valid match starts and matching string length when no match is found -1 value is returned.

Ex : regexpr(pattern, text, ignore.case=FALSE, perl=FALSE, fixed=FALSE, useBytes=FALSE)

Arguments:

  • Pattern – Character string holding a usual expression that is supposed to equal the given character vector.
  • X – Character Vector
  • Ignore.case – (False – Pattern matching works case insensitive, True – Patter matching works case sensitive)
  • Perl – To determine Perl-compatible expressions especially regexprns be used
  • Value – If a match found returns true else false
  • UseBytes – If TRUE after that the matching will be done byte-by-byte instead of character-by-character.
  • Invert – Returns indices if True

6. Gregexpr() in R String Functions

The gregexpr provide returns a list of a similar length as a text every element of which is of a similar form as the return value for regexpr, except that the preliminary positions of every (disjoint) match are given.

Syntax: gregexpr(pattern, text, ignore.case=FALSE, perl=FALSE, fixed=FALSE, useBytes=FALSE, extract=FALSE)

Arguments:

  • Pattern – Character string holding a usual expression that be supposed to equal the given character vector.
  • X – Character Vector
  • Ignore.case – (False – Pattern matching works case insensitive, True – Pattern matching works case sensitive)
  • Perl – To determine Perl-compatible expressions especially regexprns be used
  • Value – If a match found returns true else false
  • UseBytes – If TRUE after that the matching will be done byte-by-byte instead of character-by-character.
  • Invert – Returns indices if True
  • Extract – When a logical indication is matched then an extract of the substring is made and returned

7. Regexec()

The regexec() in R String Functions is very similar to regexpr() except here the indices parenthesized the corresponding sub-expressions is returned

Syntax : regexec(pattern, text, ignore.case=FALSE, perl=FALSE, fixed=FALSE, useBytes=FALSE)

Arguments:

  • Pattern – Character string holding a usual expression that can be supposed to equal the given character vector.
  • X – Character Vector
  • Ignore.case – (False – Pattern matching works case insensitive, True – Patter matching works case sensitive)
  • Perl – To determine Perl compatible expressions especially regexprns be used
  • Value – If a match found returns true else false
  • UseBytes – If TRUE after that the matching will be done byte-by-byte instead of character-by-character.
  • Invert – Returns indices if True

Recommended Articles

This has been a guide to R String Functions. Here we discussed the basic concept, Features, Manipulation of R String Functions with Example and Arguments. You can also go through our other Suggested Articles to learn more –

  1. JavaScript String Functions
  2. Oracle String Functions
  3. VBScript String Functions
  4. Regex Functions in Python (Example)

R Programming Training (12 Courses, 20+ Projects)

12 Online Courses

20 Hands-on Projects

116+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
R programming Tutorial
  • Advanced
    • Statistical Analysis with R
    • R String Functions
    • Data Exploration in R
    • R CSV Files
    • KNN Algorithm in R
    • Sorting in R
    • lm Function in R
    • Hierarchical Clustering in R
    • R Normal Distribution
    • Binomial Distribution in R
    • Decision Tree in R
    • GLM in R
    • Linear Model in R
    • Predict Function in R
    • Survival Analysis in R
    • Standard Deviation in R
    • Statistical Analysis in R
    • T-test in R
    • Database in R
  • Basic
    • What is R Programming Language
    • Careers in R Programming
    • Install R
    • List of R Packages
    • Introduction of R Tools Technology
    • R Programming Language
    • What is RStudio?
    • R-studio-Functions
    • R Packages
    • R Data Types
    • R Operators
    • Vectors in R
  • Control statement
    • If Statement in R
    • If Else Statement in R
    • Else if in R
    • Switch Statement in R
  • Loops
    • Loops in R
    • For Loop in R
    • Nested For Loop in R
    • While Loop in R
    • Next in R
  • Chart/graphs
    • Graphs in R
    • Bar Charts in R
    • Pie Chart in R
    • Histogram in R
    • Line Graph in R
    • Plot Function in R
    • Scatterplot in R
    • R Boxplot labels
  • Regression in R
    • Simple Linear Regression in R
    • Linear Regression in R
    • Multiple Linear Regression in R
    • Logistic Regression in R
    • Poisson Regression in R
    • OLS Regression in R
    • P-Value in Regression
  • Anova in R
    • ANOVA in R
    • One Way ANOVA in R
    • Two Way ANOVA in R
  • Data Structure
    • R list
    • Arrays in R
    • Data Frames in R
    • Factors in R
  • Programs
    • R Program Functions
    • Factorial in R
    • Random Number Generator in R
  • Interview question
    • R Interview Questions

Related Courses

R Programming Certification Course

Statistical Analysis Course Training

All in One Data Science Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - R Programming Training (12 Courses, 20+ Projects) Learn More