📌  相关文章
📜  R 从字符串中获取特定字符 - R 编程语言代码示例

📅  最后修改于: 2022-03-11 14:52:00.597000             🧑  作者: Mango

代码示例1
string_var = "this is an example"

# substr(string, first_char_pos, last_char_pos) # extracts characters from pos1 to pos2
substr(x, 1, 3)        # Extract first three characters
# "thi"
substr(x, 4, 4)        # Extract only the fourth character
# "s"

n_last <- 3            # Specify number of characters to extract
# nchar(x) counts total no. of characters in the string
substr(x, nchar(x) - n_last + 1, nchar(x))     # Extract last three characters
# "ple"