Reputation: 478
I have a String X
that is a List and I want to access its elements.
example:
"[('here', 29), ('negative', 1.0)]"
How can I access the 'here'
, 29
and 'negative'
?
Upvotes: 0
Views: 143
Reputation: 1751
We can also use stringr::str_split
:
library(stringr)
x <- "[('here', 29), ('negative', 1.0)]"
v1 <- str_split(x, "[[:punct:] ]")[[1]]
v1[nchar(v1)>1]
#[1] "here" "29" "negative"
Upvotes: 0
Reputation: 887851
We can use strsplit
v1 <- strsplit(x, "[[:punct:] ]")[[1]]
v1[nzchar(v1)][1:3]
#[1] "here" "29" "negative"
Upvotes: 1