从 R 编程中指定位置的字符串中提取单词 - word()函数
R 语言中的word()
函数用于从指定为参数的位置从字符串中提取单词。
Syntax: word(string, position)
Parameter:
string: From which word needs to be extracted
position: Specified Index value
示例 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)
输出:
[1] "for"
示例 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)
输出:
[1] "bcd 100 efg"