1 votes

Remove last number from each line

Comes from here

How do I remove the last number from each sentence when the number is an integer?

 df <- data.frame( col1 = c(1,2,3,4,5), 
                  col2 = c("pepe marta juan 2170","300 ww 1.4",
                           "verde 85"," verde (8383)","amarillo rojo tomate.455"))
df$col2<-as.character(df$col2)
   col1                     col2
1    1     pepe marta juan 2170
2    2               300 ww 1.4
3    3                 verde 85
4    4             verde (8383)
5    5 amarillo rojo tomate.455

The desired result would be

  col1                     col2     col3
1    1     pepe marta juan 2170    pepe marta juan
2    2               300 ww 1.4    300 ww 1.4
3    3                 verde 85    verde
4    4             verde (8383)    verde (8383)
5    5 amarillo rojo tomate.455    amarillo rojo tomate.

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X