[R] separating the integer part of a number from the fractional part

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Wed Mar 18 09:48:53 CET 2009


csrc2010 wrote:
> I have columns of decimal numbers (representing fraction day of year). I need
> to separate the fractional part of the number (to the right of the radix
> point) from the integer part. For example, if the number were '207.65' Id
> like to make a separate column which contained only '65' or even better,
> '0.65.' What I am trying to do is separate day from night. Any ideas??
> Thanks.
> -JPG

> 207.65 %%1
[1] 0.65
> 207.65 - trunc(207.65)
[1] 0.65
> 207.65 - floor(207.65)
[1] 0.65

Notice differences for negative numbers though:

> -207.65 %%1
[1] 0.35
> -207.65 - trunc(-207.65)
[1] -0.65
> -207.65 - floor(-207.65)
[1] 0.35



-- 
   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 at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list