1

Well, I got a variable that shows numbers like this one: 13015064000992062, and I need to extract the four first numbers and put it in another column. In this case, it will be 1301.

A friend told me that it was using stringr library, but he can't remember the code.

I am working with a data frame. So I need to get a new variable called "canton", that are the four first digits from 'Identificador'

So it looks like this: enter image description here

Phil
  • 7,287
  • 3
  • 36
  • 66
Jorge Paredes
  • 996
  • 7
  • 13

1 Answers1

3

We can use substr

 permMan19$newcol <- substr(permMan19$identificador, 1, 4)
akrun
  • 874,273
  • 37
  • 540
  • 662