I believe strsplit(x," +")[[1]]
will do it. (the regular expression " +"
denotes one or more spaces; strsplit
applies to character vectors, and returns a list with the splitted version of each element in the vector, so [[1]]
extracts the first (and only) component)
How to extract substrings from this string?
Question
The string is And I want to get substrings "11","1.1","282". Can anyone show me how to do this in R? Thanks!
Pas de solution correcte
Autres conseils
> x = "11 1.1 282"
> res <- strsplit(x, " +")
> res
[[1]]
[1] "11" "1.1" "282"
>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow