[R] matrix indexing/subset error

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Mon May 30 21:47:50 CEST 2016


z %% 2 == 1

has 12 logical values.  What do you expect R to do with it worth respect to 4 rows? 
-- 
Sent from my phone. Please excuse my brevity.

On May 30, 2016 11:38:46 AM PDT, Carl Sutton via R-help <r-help at r-project.org> wrote:
>Hi Guru's
>In my quest to understand R I have what I thought was a simple exercise
>that now has me baffled.  Why the error message after running this
>code?  I am totally baffled by the error message.  I was expecting rows
>1 and 3 of the x matrix to be returned, and have not a clue as to why
>this becomes a subscript difficulty.  The manual was of no help in this
>matter.
>
>x <- c(1:3,2:4)
>x  <- matrix(x, nrow = 3)
>x
>z <- c(1:4,1,1,0,0,1,0,1,0)
>z <- matrix(z, ncol = 3)
>z
>x[x[,2]>= 3,]
>x
>z %% 2 == 1
>x[z %% 2 == 1,]Error in x[z%%2 == 1, ] : (subscript) logical subscript
>too long
>Many thanks for your assistance.
>Carl Sutton CPA
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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]]



More information about the R-help mailing list