[R] matrix indexing/subset error
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:
>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
>x <- c(1:3,2:4)
>x <- matrix(x, nrow = 3)
>z <- c(1:4,1,1,0,0,1,0,1,0)
>z <- matrix(z, ncol = 3)
>z %% 2 == 1
>x[z %% 2 == 1,]Error in x[z%%2 == 1, ] : (subscript) logical subscript
>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
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help