Here is a hack, crude solution to get the digits:
Digits <- function(a){
out <- rep(NA,nchar(a))
for(i in 1:nchar(a)) out[i] <- substr(a,i,i)
return(as.numeric(out))
}
Digits(183429)
If all you want is the last three numbers, consider another hack solution:
Last3Digits <- function(a) as.numeric(substr(a,nchar(a)-2,nchar(a)))
Last3Digits(23495329)
Hope that helps. These are hack solutions, and I'm willing to bet there is
better stuff available.
-tgs
On Sun, Jan 23, 2011 at 1:39 PM, Quan Zhou <[email protected]> wrote:
> Hi Everyone,
> A quick question how to store a number like 12345 to a vector or array with
> size(1,5), like 1, 2, 3, 4, 5
> So I can compare if the last three digits of this number is the same with
> some other numbers.
>
> Thanks a lot
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [email protected] mailing list
> 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.
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
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.