Skip to content
Prev 360009 / 398503 Next

[FORGED] Re: identical() versus sapply()

Ok, I see the difference between 1 and 1:2, I'll just leave it as one of those "only in R" things.

But it seems then, that as.numeric() should guarantee a FALSE outcome, yet it does not. 

To build on what Rolf pointed out, I would really love for someone to explain this one:
num 1
int [1:2] 1 2
num [1:2] 1 2
int [1:2] 1 2

Which doubly makes no sense.  1) Either the class is "numeric" or it isn't; I did not call as.integer() here.  2) method of recasting should not affect final class.

Thanks,
Ariel


-----Original Message-----
From: Rolf Turner [mailto:r.turner at auckland.ac.nz] 
Sent: Saturday, April 09, 2016 5:27 AM
To: Jeff Newmiller
Cc: Paulson, Ariel; 'r-help at r-project.org'
Subject: Re: [FORGED] Re: [R] identical() versus sapply()
On 09/04/16 16:24, Jeff Newmiller wrote:
Interesting.  But to me counter-intuitive.  Since R makes no distinction between scalars and vectors of length 1 (or more accurately I think, since in R there is *no such thing as a scalar*, only a vector of length
1) I don't see why "1" should be treated in a manner that is categorically different from the way in which "1:2" is treated.

Can you, or someone else with deep insight into R and its rationale, explain the basis for this difference in treatment?
cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

Thread (30 messages)

Paulson, Ariel identical() versus sapply() Apr 8 Jeff Newmiller identical() versus sapply() Apr 8 Rolf Turner identical() versus sapply() Apr 9 Duncan Murdoch identical() versus sapply() Apr 9 Paulson, Ariel identical() versus sapply() Apr 11 Bert Gunter identical() versus sapply() Apr 11 Jeff Newmiller identical() versus sapply() Apr 11 Paulson, Ariel identical() versus sapply() Apr 11 William Dunlap identical() versus sapply() Apr 11 Duncan Murdoch identical() versus sapply() Apr 11 Paulson, Ariel identical() versus sapply() Apr 11 Paulson, Ariel identical() versus sapply() Apr 11 Bert Gunter identical() versus sapply() Apr 11 Duncan Murdoch identical() versus sapply() Apr 11 Rolf Turner identical() versus sapply() Apr 11 Rolf Turner identical() versus sapply() Apr 11 John Kane identical() versus sapply() Apr 12 John Kane identical() versus sapply() Apr 12 Duncan Murdoch identical() versus sapply() Apr 12 John C Nash Documentation: Was -- identical() versus sapply() Apr 12 Michael Dewey identical() versus sapply() Apr 12 Duncan Murdoch Documentation: Was -- identical() versus sapply() Apr 12 Bert Gunter Documentation: Was -- identical() versus sapply() Apr 12 John C Nash Documentation: Was -- identical() versus sapply() Apr 12 Sarah Goslee Documentation: Was -- identical() versus sapply() Apr 12 David Winsemius Documentation: Was -- identical() versus sapply() Apr 12 Duncan Murdoch Documentation: Was -- identical() versus sapply() Apr 12 Duncan Murdoch Documentation: Was -- identical() versus sapply() Apr 12 William Michels Documentation: Was -- identical() versus sapply() Apr 12 John C Nash Documentation: Was -- identical() versus sapply() Apr 12