[英]Is it possible to access characters in a string in R without using strsplit and only basic R functions?
假設我在 R 中有字符向量:
x <- "hello world"
我想單獨訪問每個元素。 我知道strsplit
中的 strsplit 可以做到這一點,但想知道是否有一種方法可以在不依賴這樣的 function 的情況下訪問元素?
如果您正在尋找替代方案,則可以使用正則表達式。 R 支持的強大工具。
library(tidyverse)
str_extract(x, "\\w+") #you ask to extract each word separated by a space. It includes words or numbers.
#the first \ is to indicate you are using regex.
希望這會有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.