matrix - quickest way in R to check that all columns are identical -
matrix - quickest way in R to check that all columns are identical -
suppose have matrix 3 columns
10 10 10 8 8 8 9 9 9 7 7 7 5 5 5 4 4 4 3 3 3 6 6 6 2 2 2 1 1 1
what fastest way check columns identical? can all
or identical
check 2 , maintain collapsing next set there more clever?
ideally, solution independent of number of columns.
you try:
all(m1[,1]==m1) # [1] true all(m2[,1]==m2) #[1] false
data m1 <- matrix(c(10:1, 10:1, 10:1), ncol=3) m2 <- cbind(m1, 11:2)
r matrix
Comments
Post a Comment