[R] matrix indexing/subset error
Carl Sutton
suttoncarl at ymail.com
Mon May 30 20:38:46 CEST 2016
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]]
More information about the R-help
mailing list