📅  最后修改于: 2022-03-11 14:51:58.714000             🧑  作者: Mango
# Two Methods to remove the first and last characters from a string variable in R:
# Example string
string = "%_adcknqwe4adflewgfgfrgaqe23_%"
# Using gsub
string_gsub <- gsub(pattern = '^.|.$', replacement = '', x = string)
# Using substr + counting characters w/ nchar():
string_substr <- substr(string, start=2, stop=nchar(string)-1)