Custom Numeric type in R
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 <ccberry at ucsd.edu> 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.
______________________________________________ R-help at 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.
______________________________________________ R-help at 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.