I'm interested in scaling one column of a matrix and then returning the whole matrix.
Suppose I have the matrix:
If I do something like:
> A[,1] * 10
I'll end up with:
However, I'd like to end up with something like:
Here's the solution I've come up with so far:
> A <- cbind(A[,1]*10, A[,2])
> A
Is this the best way to accomplish what I'd like to do?
You can assign it to the columns that is being changed
A[,1] <- A[,1]*10
A
# [,1] [,2]
#[1,] 10 2
#[2,] 30 4
A <- matrix(c(1,3,2,4), ncol=2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.