Open In App
Related Articles

Extract word from a String at specified position in R Programming – word() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
word() Function in R Language is used to extract words from a string from the position specified as argument.
Syntax: word(string, position) Parameter: string: From which word needs to be extracted position: Specified Index value
Example 1:
# R Program to illustrate 
# the use of word function
  
# Loading Library
library(stringr)
  
# Creating a string
x <- "Geeks for Geeks"
  
# Extracting word
word(x, 2)

                    
Output:
[1] "for"
Example 2:
# R Program to illustrate 
# the use of word function
  
# Loading Library
library(stringr)
  
# Creating a string
x <- "abc bcd 100 efg"
  
# Extracting words
word(x, 2, 4)

                    
Output:
[1] "bcd 100 efg"

Last Updated : 03 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads