[R] inadequacy in as.integer....

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sun Sep 11 21:00:32 CEST 2022


You seem to be confusing **what** is printed with *how* it is printed.

> print(9) ## a numeric (not an integer, actually. That would be 9L)
[1] 9   ## default print format
> print(formatC(9, width =2, flag = "0")) ## format specification
[1] "09"
> print(formatC(9, width =2, flag = "0"), quote = FALSE) # don't show quotes
[1] 09

See ?formatC and ?print.default for details

-- Bert

On Sun, Sep 11, 2022 at 9:22 AM akshay kulkarni <akshay_e4 using hotmail.com> wrote:
>
> Dear members,
>                              I came across this queer thing during my analysis:
> > as.integer("09098")
> 9098
>
> Any idea on how to retain the "0"?
>
> Yours sincerely,
> AKSHAY M KULKARNI
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list