Re: [R] spliting an integer

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Fri 21 Oct 2005 - 06:50:16 EST

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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Oct 21 07:53:17 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:46 EST