Re: [R] spliting an integer

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Fri 21 Oct 2005 - 07:42:23 EST

"Anne Hertel" <ahertel@atmos.uiuc.edu> writes:

> Hi Dimitri,
>
> You could write
>
> > z <- trunc(x/10000)
> > z
> [1] 1 12 8
> > y <- x-trunc(x/10000)*10000
> > y
> [1] 1999 2000 1997
>
> And there you have it.

Er, we do have integer divide and remainder operators:

> X = c(11999, 122000, 81997)
> X %% 1e4
[1] 1999 2000 1997
> X %/% 1e4

[1] 1 12 8

> Cheers,
> Anne Hertel
>
>
> On Thu, 20 Oct 2005 17:40:10 -0200
> "Dimitri Szerman" <dimitrijoe@ipea.gov.br> 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]]
> >
> >______________________________________________
> >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
>
>
>
> ------------------------------------------------------------
> Anne M. K. Hertel
> Grad. Student & Research Assistant
> Department of Atmospheric Sciences
> University of Illinois at Urbana-Champaign
> Annex II, room 204
> Phone: (217) 333 6296
>
> ______________________________________________
> 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
>

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
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 09:06:32 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 19:14:58 EST