How to remove the last letter or number from text data?

Let’s say you want to remove the last one or two letters from a given text data to make it look like below.

You can use ‘str_sub’ function for this, and want to use negative position for the ending position.

str_sub(<column_name>, 1, -2)

The above means, keep the text from the 1st position to ‘the 2nd from the last’ position.

The entire ‘mutate’ command would look like this.

mutate(new_column = str_sub(parts_number, 1, -2))