Home > Blockchain >  how to remove last 0 from values in row
how to remove last 0 from values in row

Time:10-18

I have one data frame which looks like this in that one column looks like this :-

col1

0.100

0.200

0.300

0.400

0.500

now I want to remove last zero from row. how I can do that any idea?

desired output.

col1

0.10

0.20

0.30

and so on!

thanks in advance .

CodePudding user response:

I understand your column is of class character? In that case, you can use a pattern replacement. This will take care of removing the last zero all your values.

data <- data.frame(digit = c("0.100", "0.200", "0.300", "0.400", "0.500"))
data$digit <- gsub("0$", "", data$digit)
  •  Tags:  
  • r
  • Related