I have a column with codes of 4 characters and I would like to make a second column which only gives the first 3 characters of the first columns.
So if the first code is 1234 I would like to have 123 in the second column.
I am currently looking into gsub and with the following code I can display the first character.
code<-1234
gsub("(?<!^)(..)", "", code, perl=TRUE)
Does anyone know how I could extract the first three characters?
substr(code, 1, 3)
orsub("^(.{3}).*", "\\1", code)
– akrun