r - remove last but one character from every field
问题 the substr() function in R can isolate any character by position e.g. substr(df$10,2,3) or by using nchar() it is possible to work backwards from the end of the field to isolate a character in a position such as last but one using: substr(df$10,nchar(df$10)-2,nchar(df$10)-1) however I would like to know how to simply remove the last but one character of every field for a column in a dataframe. I am having difficulty doing this. any help would be great! 回答1: You can use a regular expression