Get First Element from Character String Split in R (Example Code)
This article shows how to extract the first part after splitting a character string in the R programming language.
Creation of Example Data
x <- "What an amazing character string in R" # Example string x # Display example string # [1] "What an amazing character string in R" |
x <- "What an amazing character string in R" # Example string x # Display example string # [1] "What an amazing character string in R"
Example: Extracting First Element of Character String Split
strsplit(x, " ")[[1]][1] # Return first entry of string # [1] "What" |
strsplit(x, " ")[[1]][1] # Return first entry of string # [1] "What"
Related Articles & Further Resources
You may find some related R tutorials on topics such as data conversion, data objects, naming data, and character strings below.