どうも、ちょげ(@chogetarou)です。
文字列(string)の末尾の文字を取得する方法を紹介します。
方法

文字列(string)の最後の文字を取得するには、substr()を使います。
まず、substr()を呼び出します。
substr()の第1引数に文字列を指定します。
substr()の第2引数と第3引数に文字列の文字数を指定します。
#text=対象の文字列
size <- nchar(text) #文字数
result <- substr(text, size, size)
上記のsubstr()は、第1引数に指定した文字列(string)の最後の文字を取得します。
使用例
text <- "Hello,World"
size <- nchar(text)
result <- substr(text, size, size)
result
出力:
> result
[1] "d"
コメント