[R] matrix indexing/subset error
suttoncarl at ymail.com
Mon May 30 20:38:46 CEST 2016
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)
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 too long
Many thanks for your assistance.
Carl Sutton CPA
[[alternative HTML version deleted]]
More information about the R-help