How to use strsplit() function in R? - JournalDev - R Programming

How to use strsplit() function in R? - JournalDev - R Programming

strsplit() function in R - strsplit() is an exceptional R function, which splits the input string vector into sub-strings. Now, let’s see how we can split a string vector using the strsplit().

As a programmer, you may need to work on tons of strings. You will perform concatenation and splitting of them very often. There comes the strsplit() function in R. In a previous article, we have discussed the paste() function to concatenate the strings. Now, let’s see how we can split a string vector using the strsplit().

strsplit() is an exceptional R function, which splits the input string vector into sub-strings. Let’s see how this function works and what are all the ways to perform splitting of the strings in R using the strsplit().

Table of Contents[



Strsplit() Function Syntax

Strsplit(): An R Language function which is used to split the strings into substrings with split arguments.




  • X = input data file, vector or a stings.
  • Split = Splits the strings into required formats.
  • Fixed = Matches the split or uses the regular expression.

Use strsplit() function in R – Implementation

In this section, let’s see a simple example that shows the use case of the strsplit() function. In this case, the strsplit() function will split the given input into a list of strings or values.

Let’s see how it works.



df<-(``"R is the statistical analysis language"``)

strsplit``(df, split = " "``)

Output =

"R" "is" "the" "statistical" "analysis" "language"

We have done it! In this way, we can easily split the strings present in the data. One of the best use cases of strsplit() function is in plotting the word clouds. In that, we need tons of word strings to plot the most popular or repeated word. So, in order to get the strings from the data we use this function which returns the list of strings.

1. Using strsplit() function with delimiter

A delimiter in general is a simple symbol, character, or value that separates the words or text in the data. In this section, we will be looking into the use of various symbols as delimiters.




strsplit``(df,split = '%'``)

Output =

"get" "better" "every"  "day"  

In this case, the input text has the % as a delimiter. Now, our concern is to remove the delimiter and get the text as a list of strings. The strsplit() function has done the same here. It removed the delimiter and returned the strings as a list.

r programming function

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Functional Programming

Functional Programming: Functional Programming is a Declarative style of Programming Paradigm for writing computer programs.

Are functions from programming really functions?

Are functions from programming really functions? If you are reading this, then most probably you already know quite well what functions are in programming.

Quantile() function in R - A brief guide - JournalDev R Programming %

You can easliy generate the quantiles in R using the quantile() function. A qunatile is nothing but a sample which is divided into equal groups or sizes.

R Programming Course

🔵 Intellipaat Data Science with R course: this R Tutorial For Beginners video, you will learn r pr...

cbind() function in R programming

You can use cbind() function in R exclusively to bind or combine the multiple columns together. Hello folks, today, our focus will be on the applications