To get a character at a specific index in a string in R, you can use array-like indexing.
In this example,
str
with a value of "Hello World"
.str
.str <- "Hello World"
charAtIndex6 <- str[6]
print(paste("Character at index 6:", charAtIndex6))
[1] "Character at index 6: W"
In this example,
str
with a value of "R"
.str
.str <- "R"
charAtIndex2 <- str[2]
print(paste("Character at index 2:", charAtIndex2))
[1] "Character at index 2: R"
In this tutorial, we learned How to get Character at Specific Index in String in R language with well detailed examples.