[R] spliting an integer
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Thu Oct 20 22:50:16 CEST 2005
Dimitri Szerman wrote:
> Hi there,
>
>>From the vector X of integers,
>
> X = c(11999, 122000, 81997)
>
> I would like to make these two vectors:
>
> Z= c(1999, 2000, 1997)
> Y =c(1 , 12 , 8)
>
> That is, each entry of vector Z receives the four last digits of each entry of X, and Y receives "the rest".
>
> Any suggestions?
>
> Thanks in advance,
>
> Dimitri
> [[alternative HTML version deleted]]
Try:
X <- c(11999, 122000, 81997)
Y <- X %/% 10000
Z <- X - Y * 10000
See ?Arithmetic for more details.
HTH,
--sundar
More information about the R-help
mailing list