I have matrix A with 1 column, and I want to create a new matrix B with some numbers from A. More precisely
B[1-10] <- A[2-6, and 11-16]
Do anyone know how to do this?
Thanks in advance!
Say we have this example matrix:
# example 1 column matrix
A <- matrix(1:20, ncol = 1)
We can subset the 1st column and selected rows:
B <- A[ c(2:6, 11:16), 1 ]
dim(B)
# NULL
class(B)
# [1] "integer"
Notice above will give us an integer vector. To keep it as matrix after subsetting use drop = FALSE
:
B <- A[ c(2:6, 11:16), 1, drop = FALSE ]
dim(B)
# [1] 11 1
class(B)
# [1] "matrix"
Hard to say without example but try this:
B = as.matrix (c(A[2:6,1],A[11:16,1]))
B <- A[ c(2:6, 11:16), 1 ]
?-
is subtraction,:
is sequence