I want to give the numerical data of CSV data a previous zero.I'd like to add the previous 0 to the single digit number.
Please tell me who it is.
Included in tidyverse to change the "appearance" of the number
The library(stringr) str_pad() is useful.
pacman:p_load(tidyverse)
>somedata<-10
>somedata
[1] 10
>str(somedata)# data is numeric
num10
>str_pad(somedata,6,pad="0")
[1] "000010"
>str_pad(somedata,6,pad="0")%>%str
chr "000010"
# The data has been converted to a character
The numeric object can only hold pure numbers, so
to the character type to add unnecessary zeros
Please note that the results have been converted.
The simplest way to distinguish is to see if the output of the results is enclosed in double quotes.
[1]10
[1] "000010"
© 2024 OneMinuteCode. All rights reserved.