I have a dataframe that contains numbers with a fixed number of decimals (five)
data <- data_frame(number = c(1.43010, 1.43011, 1.43012 ,1.43013))
# A tibble: 4 × 1
number
<dbl>
1 2.43010
2 2.43011
3 2.43012
4 2.43013
What I need to do is extract the two last characters of each number
. But doing:
mutate(data, extract = str_sub(as.character(number),-2,-1))
# A tibble: 4 × 2
number extract
<dbl> <chr>
1 1.43010 01
2 1.43011 11
3 1.43012 12
4 1.43013 13
fails because the zero in 2.43010
disappears during the conversion.
What can I do here? Thanks!