[R] complain about a[-integer(0)]

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Sat Oct 11 16:29:01 CEST 2014


I don't understand what you think it should actually return.  As for why it should behave the way it does now... hmmm, keep in mind that each sub-expression needs to make sense as well. 

Consider -integer(0)... applying the unary negation operator to a vector of integers yields a new vector of the same length as the original one where each element has had its sign changed. If there are no elements in the vector to begin with, there should be no elements in the result. With no elements in the result, there is nowhere to for the negative sign to have an effect. Thus, -integer(0) is the same as integer(0). R would have to recognize the -integer(0) expression as a whole and treat it specially to get a different result than the result it gives now, and I don't like the idea that length(a[-integer(0)]) might be non-zero as a special case even though length(integer(0)) is zero. So, no, I definitely don't agree with you.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On October 11, 2014 2:25:14 AM PDT, PO SU <rhelpmaillist at 163.com> wrote:
>
>Dear helpeRs,
>    let a <- 1:10 
>    let b <- integer(0) first, then i will randomly write a integer
>differently in the range(1,10)  or NULL into b. for supposed 5 times. 
>   then i want to get a[-b],that means i not want the values at index
>b. 
>   if any time of  5 times generate a integer, it works fine. but when
>all the 5 times generate NULL, it can't work!
>  Because of  the  a[-integer(0)] =integer(0) .
>  I ask the same question once before, now i encount it again, i think
>a[-integer(0)] should return a not integer(0) !
>  Is any one have the same idea with me ? or give me a oppisite case
>that a[-integer(0)] need to be integer(0) ?
> 
>
>
>
>
>--
>
>PO SU
>mail: desolator88 at 163.com 
>Majored in Statistics from SJTU
>______________________________________________
>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.



More information about the R-help mailing list