An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111030/d59404cb/attachment.pl>
why the a[-indx] does not work?
12 messages · Alaios, Duncan Murdoch, William Dunlap +3 more
On 11-10-30 2:52 PM, Alaios wrote:
Dear all, Could you please explain me why
OverloadsTesT
[1] 1 0 1 0 0 0 0 0 0 0
a<-matrix(data=seq(1,10),nrow=10) a
[,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 [8,] 8 [9,] 9 [10,] 10
a[-OverloadsTesT]
[1] 2 3 4 5 6 7 8 9 10 the last line does not remove the first and third element and only does the first element.? What I want to do is for zeros to return the elements and for any positive value to remove it. What I am doing wrong?
You are asking it to remove item 1, and it does. If you want to negate a logical vector, you need to use a logical vector and negate it, e.g. OverloadsTesT <- as.logical(OverloadsTeSt) a[!OverloadsTest] Duncan Murdoch
a[overLoadTesT==0]
[1] 2 4 5 6 7 8 9 10
Look into help('[') or help('Subscript') to see
how integer and logical (Boolean) subscripts differ.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alaios Sent: Sunday, October 30, 2011 11:52 AM To: R-help at r-project.org Subject: [R] why the a[-indx] does not work? Dear all, Could you please explain me why
OverloadsTesT
[1] 1 0 1 0 0 0 0 0 0 0
a<-matrix(data=seq(1,10),nrow=10) a
[,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 [8,] 8 [9,] 9 [10,] 10
a[-OverloadsTesT]
[1] 2 3 4 5 6 7 8 9 10 the last line does not remove the first and third element and only does the first element.? What I want to do is for zeros to return the elements and for any positive value to remove it. What I am doing wrong? B.R Alex [[alternative HTML version deleted]]
______________________________________________ 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.
Duncan Murdoch-2 wrote:
On 11-10-30 2:52 PM, Alaios wrote:
Dear all, Could you please explain me why
OverloadsTesT
[1] 1 0 1 0 0 0 0 0 0 0
a<-matrix(data=seq(1,10),nrow=10) a
[,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 [8,] 8 [9,] 9 [10,] 10
a[-OverloadsTesT]
[1] 2 3 4 5 6 7 8 9 10 the last line does not remove the first and third element and only does the first element.? What I want to do is for zeros to return the elements and for any positive value to remove it. What I am doing wrong?
You are asking it to remove item 1, and it does. If you want to negate a logical vector, you need to use a logical vector and negate it, e.g. OverloadsTesT <- as.logical(OverloadsTeSt) a[!OverloadsTest] Duncan Murdoch
Or: a[-c(1,3)]
David. -- View this message in context: http://r.789695.n4.nabble.com/why-the-a-indx-does-not-work-tp3953737p3953815.html Sent from the R help mailing list archive at Nabble.com.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111030/91f4cc30/attachment.pl>
ifelse(myvec == 0, FALSE, TRUE) # set 0 to FALSE, other values to TRUE
On Sun, Oct 30, 2011 at 3:50 PM, Alaios <alaios at yahoo.com> wrote:
probably you mean For ?[?-indexing only: ?i?, ?j?, ?...? can be logical vectors, indicating elements/slices to select. ?Such vectors are recycled if necessary to match the corresponding extent. ?i?, ?j?, ?...? can also be negative integers, indicating elements/slices to leave out of the selection. How can i convert the positives to TRUE and zeros and FALSE?
________________________________
From: William Dunlap <wdunlap at tibco.com>
Sent: Sunday, October 30, 2011 9:17 PM
Subject: RE: [R] why the a[-indx] does not work?
? > a[overLoadTesT==0]
? [1]? 2? 4? 5? 6? 7? 8? 9 10
Look into help('[') or help('Subscript') to see
how integer and logical (Boolean) subscripts differ.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alaios
Sent: Sunday, October 30, 2011 11:52 AM
To: R-help at r-project.org
Subject: [R] why the a[-indx] does not work?
Dear all,
Could you please explain me why
OverloadsTesT
[1] 1 0 1 0 0 0 0 0 0 0
a<-matrix(data=seq(1,10),nrow=10)
a
[,1]
[1,]? ? 1
[2,]? ? 2
[3,]? ? 3
[4,]? ? 4
[5,]? ? 5
[6,]? ? 6
[7,]? ? 7
[8,]? ? 8
[9,]? ? 9
[10,]? ?10
a[-OverloadsTesT]
[1]? 2? 3? 4? 5? 6? 7? 8? 9 10
the last line does not remove the first and third element and only does the first element.?
What I want to do is for zeros to return the elements and for any positive value to remove it.
What I am doing wrong?
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111030/571cdb1e/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111030/712744a6/attachment.pl>
myvec != 0 does the same as ifelse(myvec == 0, FALSE, TRUE) but more quickly Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Sarah Goslee Sent: Sunday, October 30, 2011 12:57 PM To: Alaios Cc: R-help at r-project.org Subject: Re: [R] why the a[-indx] does not work? ifelse(myvec == 0, FALSE, TRUE) # set 0 to FALSE, other values to TRUE On Sun, Oct 30, 2011 at 3:50 PM, Alaios <alaios at yahoo.com> wrote:
probably you mean For '['-indexing only: 'i', 'j', '...' can be logical vectors, indicating elements/slices to select. ?Such vectors are recycled if necessary to match the corresponding extent. 'i', 'j', '...' can also be negative integers, indicating elements/slices to leave out of the selection. How can i convert the positives to TRUE and zeros and FALSE?
________________________________
From: William Dunlap <wdunlap at tibco.com>
Sent: Sunday, October 30, 2011 9:17 PM
Subject: RE: [R] why the a[-indx] does not work?
? > a[overLoadTesT==0]
? [1]? 2? 4? 5? 6? 7? 8? 9 10
Look into help('[') or help('Subscript') to see
how integer and logical (Boolean) subscripts differ.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alaios
Sent: Sunday, October 30, 2011 11:52 AM
To: R-help at r-project.org
Subject: [R] why the a[-indx] does not work?
Dear all,
Could you please explain me why
OverloadsTesT
[1] 1 0 1 0 0 0 0 0 0 0
a<-matrix(data=seq(1,10),nrow=10)
a
[,1]
[1,]? ? 1
[2,]? ? 2
[3,]? ? 3
[4,]? ? 4
[5,]? ? 5
[6,]? ? 6
[7,]? ? 7
[8,]? ? 8
[9,]? ? 9
[10,]? ?10
a[-OverloadsTesT]
[1]? 2? 3? 4? 5? 6? 7? 8? 9 10
the last line does not remove the first and third element and only does the first element.?
What I want to do is for zeros to return the elements and for any positive value to remove it.
What I am doing wrong?
______________________________________________ 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.
I like to use numericVector != 0 instead of is.logical(numericVector) because the former more directly indicates what you want to happen instead of relying on knowledge that numeric 0 maps to logical FALSE. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alaios Sent: Sunday, October 30, 2011 1:40 PM To: andrija djurovic Cc: R-help at r-project.org Subject: Re: [R] why the a[-indx] does not work? I think this does the work return(m[!as.logical(data)]) I am not sure though if this is the same with return(m[!as.logical(data)])
________________________________
From: andrija djurovic <djandrija at gmail.com>
Cc: "R-help at r-project.org" <R-help at r-project.org>
Sent: Sunday, October 30, 2011 9:58 PM
Subject: Re: [R] why the a[-indx] does not work?
as.logical(c(1,0,1,1))
[1] ?TRUE FALSE ?TRUE ?TRUE
?as.logical
probably you mean
For ?[?-indexing only: ?i?, ?j?, ?...? can be logical
vectors, indicating elements/slices to select. ?Such vectors
are recycled if necessary to match the corresponding extent.
?i?, ?j?, ?...? can also be negative integers, indicating
elements/slices to leave out of the selection.
How can i convert the positives to TRUE and zeros and FALSE?
________________________________
From: William Dunlap <wdunlap at tibco.com>
Sent: Sunday, October 30, 2011 9:17 PM
Subject: RE: [R] why the a[-indx] does not work?
? > a[overLoadTesT==0]
? [1]? 2? 4? 5? 6? 7? 8? 9 10
Look into help('[') or help('Subscript') to see
how integer and logical (Boolean) subscripts differ.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alaios
Sent: Sunday, October 30, 2011 11:52 AM
To: R-help at r-project.org
Subject: [R] why the a[-indx] does not work?
Dear all,
Could you please explain me why
OverloadsTesT
[1] 1 0 1 0 0 0 0 0 0 0
a<-matrix(data=seq(1,10),nrow=10)
a
[,1]
[1,]? ? 1
[2,]? ? 2
[3,]? ? 3
[4,]? ? 4
[5,]? ? 5
[6,]? ? 6
[7,]? ? 7
[8,]? ? 8
[9,]? ? 9
[10,]? ?10
a[-OverloadsTesT]
[1]? 2? 3? 4? 5? 6? 7? 8? 9 10
the last line does not remove the first and third element and only does the first element.?
What I want to do is for zeros to return the elements and for any positive value to remove it.
What I am doing wrong?
B.R
Alex
??? [[alternative HTML version deleted]]
______________________________________________
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.
? ? ? ?[[alternative HTML version deleted]]
______________________________________________
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.
[[alternative HTML version deleted]]
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111030/3d18e53a/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111030/ce55b53f/attachment.pl>