Discussion:
[R] complain about a[-integer(0)]
PO SU
2014-10-11 09:25:14 UTC
Permalink
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
Jim Lemon
2014-10-11 09:57:40 UTC
Permalink
Post by PO SU
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
Post by PO SU
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
Post by PO SU
idea with me ? or give me a oppisite case that a[-integer(0)] need to
be
Post by PO SU
integer(0) ?
Hi PO SU,
How about:

if(length(b)) a<-a[-b]

Jim
PO SU
2014-10-11 10:41:12 UTC
Permalink
Tks, i have to do it.....





--

PO SU
mail: desolator88 at 163.com
Majored in Statistics from SJTU
Post by Jim Lemon
Post by PO SU
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
Post by PO SU
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
Post by PO SU
idea with me ? or give me a oppisite case that a[-integer(0)] need to
be
Post by PO SU
integer(0) ?
Hi PO SU,
if(length(b)) a<-a[-b]
Jim
[[alternative HTML version deleted]]
Jeff Newmiller
2014-10-11 14:29:01 UTC
Permalink
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.
Post by PO SU
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.
Loading...