[R] reverse truncate to extract only decimal values

2009-04-16 Thread T.D.Rudolph

hello there,

Is there a way of truncating in the opposite direction so as to retain only
the values to the right of the decimal??

i.e. rather than:
 trunc(39.5)
[1] 39

i would get something like:
 revtrunc(39.5)
[1] 0.5

I've been searching to no avail but I imagine there is a very simple
solution!
Tyler
-- 
View this message in context: 
http://www.nabble.com/%22reverse-truncate%22-to-extract-only-decimal-values-tp23086851p23086851.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] reverse truncate to extract only decimal values

2009-04-16 Thread Sarah Goslee
You could do something like this:

 revtrunc - function(x) { x - floor(x) }

 revtrunc(39.5)
[1] 0.5

But note:
 revtrunc(-39.5)
[1] 0.5

I'm not sure what you'd want for negative numbers. One possibility:

revtrunc - function(x) { sign(x) * (x - floor(x)) }
 revtrunc(39.5)
[1] 0.5
 revtrunc(-39.5)
[1] -0.5

Sarah

On Thu, Apr 16, 2009 at 5:30 PM, T.D.Rudolph prairie.pic...@gmail.com wrote:

 hello there,

 Is there a way of truncating in the opposite direction so as to retain only
 the values to the right of the decimal??

 i.e. rather than:
 trunc(39.5)
 [1] 39

 i would get something like:
 revtrunc(39.5)
 [1] 0.5

 I've been searching to no avail but I imagine there is a very simple
 solution!
 Tyler



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org 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.


Re: [R] reverse truncate to extract only decimal values

2009-04-16 Thread Paul Smith
On Thu, Apr 16, 2009 at 10:30 PM, T.D.Rudolph prairie.pic...@gmail.com wrote:
 Is there a way of truncating in the opposite direction so as to retain only
 the values to the right of the decimal??

 i.e. rather than:
 trunc(39.5)
 [1] 39

 i would get something like:
 revtrunc(39.5)
 [1] 0.5

 I've been searching to no avail but I imagine there is a very simple
 solution!

revtrunc - function(x) x-trunc(x)

Paul

__
R-help@r-project.org 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.


Re: [R] reverse truncate to extract only decimal values

2009-04-16 Thread Barry Rowlingson
On Thu, Apr 16, 2009 at 10:30 PM, T.D.Rudolph prairie.pic...@gmail.com wrote:

 hello there,

 Is there a way of truncating in the opposite direction so as to retain only
 the values to the right of the decimal??

 i.e. rather than:
 trunc(39.5)
 [1] 39

 i would get something like:
 revtrunc(39.5)
 [1] 0.5

 I've been searching to no avail but I imagine there is a very simple
 solution!

 'minus'?

 x - trunc(x) ?

Barry

__
R-help@r-project.org 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.


Re: [R] reverse truncate to extract only decimal values

2009-04-16 Thread T.D.Rudolph

This one really sheds light on that old adage
...When you can't see the forest for the trees!



Sarah Goslee wrote:
 
 You could do something like this:
 
 revtrunc - function(x) { x - floor(x) }
 
 revtrunc(39.5)
 [1] 0.5
 
 But note:
 revtrunc(-39.5)
 [1] 0.5
 
 I'm not sure what you'd want for negative numbers. One possibility:
 
 revtrunc - function(x) { sign(x) * (x - floor(x)) }
 revtrunc(39.5)
 [1] 0.5
 revtrunc(-39.5)
 [1] -0.5
 
 Sarah
 
 On Thu, Apr 16, 2009 at 5:30 PM, T.D.Rudolph prairie.pic...@gmail.com
 wrote:

 hello there,

 Is there a way of truncating in the opposite direction so as to retain
 only
 the values to the right of the decimal??

 i.e. rather than:
 trunc(39.5)
 [1] 39

 i would get something like:
 revtrunc(39.5)
 [1] 0.5

 I've been searching to no avail but I imagine there is a very simple
 solution!
 Tyler
 
 
 
 -- 
 Sarah Goslee
 http://www.functionaldiversity.org
 
 __
 R-help@r-project.org 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.
 
 

-- 
View this message in context: 
http://www.nabble.com/%22reverse-truncate%22-to-extract-only-decimal-values-tp23086851p23087144.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.