Quantcast

Custom Numeric type in R

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Custom Numeric type in R

Bogaso
Hi again,

In R, there are various numerics like, NA, Inf, or simple integers etc.
However I want to include one custom type: "TBD", which R should treat as
numeric, not character.

That "TBD" should have same property like Inf, however except this: TBD -
TBD = 0

In future, I am planning to add few more properties to TBD.

Can somebody guide me if this is possible in R, ans also some pointer on
how can be done in R

Thanks and regards,

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom Numeric type in R

Charles Berry
Christofer Bogaso <bogaso.christofer <at> gmail.com> writes:

>
> Hi again,
>
> In R, there are various numerics like, NA, Inf, or simple integers etc.
> However I want to include one custom type: "TBD", which R should treat as
> numeric, not character.
>
> That "TBD" should have same property like Inf, however except this: TBD -
> TBD = 0
>
> In future, I am planning to add few more properties to TBD.
>
> Can somebody guide me if this is possible in R, ans also some pointer on
> how can be done in R
>

Possible? Yes.

Your question might be framed as

"How do I create a class and write a method for '-' that does ... ?"

The answer is "learn about methods and classes in R".

To get started, see

 ?methods
 ?class
 ?groupGenericFunction-class
 ?groupGeneric

and follow the links therein.


Check the posting guide. If you need to follow up, you should consider
whether the question you have fits better on R-devel.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom Numeric type in R

Bert Gunter
Charles:

That was my initial thought, too. But then I wondered whether what was
meant was to use "TBD" as an alternative kind of numeric value that
would be part of numeric vectors, lists, etc.  in the same way that NA
or Inf is. It is not clear to me that a new object class provides a
way to do this, at least not without a large amount of recreating
standard R objects and the operations on them to include a "TBD" type
numeric. My understanding is that NA and Inf are built into R's
internals as part of IEEE floating point standards. I do not know how
or if one can add new numeric types to these.

I would appreciate correction of any misunderstanding that I have and
further details as to how one would do this.

Best,
Bert

On Sun, Nov 10, 2013 at 9:49 AM, Charles Berry <[hidden email]> wrote:

> Christofer Bogaso <bogaso.christofer <at> gmail.com> writes:
>
>>
>> Hi again,
>>
>> In R, there are various numerics like, NA, Inf, or simple integers etc.
>> However I want to include one custom type: "TBD", which R should treat as
>> numeric, not character.
>>
>> That "TBD" should have same property like Inf, however except this: TBD -
>> TBD = 0
>>
>> In future, I am planning to add few more properties to TBD.
>>
>> Can somebody guide me if this is possible in R, ans also some pointer on
>> how can be done in R
>>
>
> Possible? Yes.
>
> Your question might be framed as
>
> "How do I create a class and write a method for '-' that does ... ?"
>
> The answer is "learn about methods and classes in R".
>
> To get started, see
>
>  ?methods
>  ?class
>  ?groupGenericFunction-class
>  ?groupGeneric
>
> and follow the links therein.
>
>
> Check the posting guide. If you need to follow up, you should consider
> whether the question you have fits better on R-devel.
>
> ______________________________________________
> [hidden email] 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.



--

Bert Gunter
Genentech Nonclinical Biostatistics

(650) 467-7374

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom Numeric type in R

Rui Barradas
Hello,

Try the following.

 > class(NA)
[1] "logical"
 > class(NaN)
[1] "numeric"
 > class(Inf)
[1] "numeric"


So my guess is that what the op wants is not possible. And that to
declare a new class shouldn't solve the problem.

Rui Barradas

Em 10-11-2013 21:07, Bert Gunter escreveu:

> Charles:
>
> That was my initial thought, too. But then I wondered whether what was
> meant was to use "TBD" as an alternative kind of numeric value that
> would be part of numeric vectors, lists, etc.  in the same way that NA
> or Inf is. It is not clear to me that a new object class provides a
> way to do this, at least not without a large amount of recreating
> standard R objects and the operations on them to include a "TBD" type
> numeric. My understanding is that NA and Inf are built into R's
> internals as part of IEEE floating point standards. I do not know how
> or if one can add new numeric types to these.
>
> I would appreciate correction of any misunderstanding that I have and
> further details as to how one would do this.
>
> Best,
> Bert
>
> On Sun, Nov 10, 2013 at 9:49 AM, Charles Berry <[hidden email]> wrote:
>> Christofer Bogaso <bogaso.christofer <at> gmail.com> writes:
>>
>>>
>>> Hi again,
>>>
>>> In R, there are various numerics like, NA, Inf, or simple integers etc.
>>> However I want to include one custom type: "TBD", which R should treat as
>>> numeric, not character.
>>>
>>> That "TBD" should have same property like Inf, however except this: TBD -
>>> TBD = 0
>>>
>>> In future, I am planning to add few more properties to TBD.
>>>
>>> Can somebody guide me if this is possible in R, ans also some pointer on
>>> how can be done in R
>>>
>>
>> Possible? Yes.
>>
>> Your question might be framed as
>>
>> "How do I create a class and write a method for '-' that does ... ?"
>>
>> The answer is "learn about methods and classes in R".
>>
>> To get started, see
>>
>>   ?methods
>>   ?class
>>   ?groupGenericFunction-class
>>   ?groupGeneric
>>
>> and follow the links therein.
>>
>>
>> Check the posting guide. If you need to follow up, you should consider
>> whether the question you have fits better on R-devel.
>>
>> ______________________________________________
>> [hidden email] 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.
>
>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom Numeric type in R

Duncan Murdoch-2
On 13-11-10 4:52 PM, Rui Barradas wrote:
> Hello,
>
> Try the following.
>
>   > class(NA)
> [1] "logical"

This doesn't actually prove anything, since there are multiple different
objects that display as NA.  For example:

 > 1+NA
[1] NA
 > class(1+NA)
[1] "numeric"

See ?"NA" for other ways to represent the other NA values.


>   > class(NaN)
> [1] "numeric"
>   > class(Inf)
> [1] "numeric"
>
>
> So my guess is that what the op wants is not possible. And that to
> declare a new class shouldn't solve the problem.

I don't think it is impossible, but I think it would be hard to get it
working well.

Duncan Murdoch

>
> Rui Barradas
>
> Em 10-11-2013 21:07, Bert Gunter escreveu:
>> Charles:
>>
>> That was my initial thought, too. But then I wondered whether what was
>> meant was to use "TBD" as an alternative kind of numeric value that
>> would be part of numeric vectors, lists, etc.  in the same way that NA
>> or Inf is. It is not clear to me that a new object class provides a
>> way to do this, at least not without a large amount of recreating
>> standard R objects and the operations on them to include a "TBD" type
>> numeric. My understanding is that NA and Inf are built into R's
>> internals as part of IEEE floating point standards. I do not know how
>> or if one can add new numeric types to these.
>>
>> I would appreciate correction of any misunderstanding that I have and
>> further details as to how one would do this.
>>
>> Best,
>> Bert
>>
>> On Sun, Nov 10, 2013 at 9:49 AM, Charles Berry <[hidden email]> wrote:
>>> Christofer Bogaso <bogaso.christofer <at> gmail.com> writes:
>>>
>>>>
>>>> Hi again,
>>>>
>>>> In R, there are various numerics like, NA, Inf, or simple integers etc.
>>>> However I want to include one custom type: "TBD", which R should treat as
>>>> numeric, not character.
>>>>
>>>> That "TBD" should have same property like Inf, however except this: TBD -
>>>> TBD = 0
>>>>
>>>> In future, I am planning to add few more properties to TBD.
>>>>
>>>> Can somebody guide me if this is possible in R, ans also some pointer on
>>>> how can be done in R
>>>>
>>>
>>> Possible? Yes.
>>>
>>> Your question might be framed as
>>>
>>> "How do I create a class and write a method for '-' that does ... ?"
>>>
>>> The answer is "learn about methods and classes in R".
>>>
>>> To get started, see
>>>
>>>    ?methods
>>>    ?class
>>>    ?groupGenericFunction-class
>>>    ?groupGeneric
>>>
>>> and follow the links therein.
>>>
>>>
>>> Check the posting guide. If you need to follow up, you should consider
>>> whether the question you have fits better on R-devel.
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>
>>
>>
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Loading...