Re: [R] create new matrices with specific patterns

2015-01-27 Thread JSHuang3181
Hi, It appears that you want B to be rows 1 thru 4, 6 thru 9, 11 thru 14 and 16 thru 17 from A. B - A[c(1:4, 6:9, 11:14, 16:17),] E - A[16:19,] -- View this message in context: http://r.789695.n4.nabble.com/create-new-matrices-with-specific-patterns-tp4702350p4702354.html Sent from the R

Re: [R] create new matrices with specific patterns

2015-01-27 Thread Jim Lemon
Hi Kathryn, Selecting the elements of matrix A as you describe is not too difficult: select_A-function(A,B) { thisA-A[A[,1] == B$p[1],] newmat-matrix(c(rep(p[1],B$nq[1]),rep(thisA[,2],length.out=B$nq[1])),ncol=2) for(i in 2:dim(B)[1]) { thisA-A[A[,1] == B$p[i],] newmat- rbind(newmat,

[R] create new matrices with specific patterns

2015-01-26 Thread Kathryn Lord
Dear R users, Suppose I have a matrix A. p - 1:4 q - 1:5 P-rep(p, each=5) Q-rep(q, 4) A - cbind(P,Q) A P Q [1,] 1 1 [2,] 1 2 [3,] 1 3 [4,] 1 4 [5,] 1 5 [6,] 2 1 [7,] 2 2 [8,] 2 3 [9,] 2 4 [10,] 2 5 [11,] 3 1 [12,] 3 2 [13,] 3 3 [14,] 3 4 [15,] 3 5 [16,] 4 1 [17,] 4 2 [18,]

Re: [R] create new matrices with specific patterns

2015-01-26 Thread Kathryn Lord
Sorry for inconvenience. For clarification, The matrix B looks like B P Q [1,] 1 1 [2,] 1 2 [3,] 1 3 [4,] 1 4 [5,] 2 1 [6,] 2 2 [7,] 2 3 [8,] 2 4 [9,] 3 1 [10,] 3 2 [11,] 3 3 [12,] 3 4 [13,] 4 1 [14,] 4 2 The matrix E is E P Q [1,] 4 1 [2,] 4 2 [3,] 4 3 [4,] 4 4 On