Reputation: 1247
I am new to R (or any programming language) I want to run a for loop along a selected rows of a Matrix, say 3,5,6,8. I know how to do it for a continuous range. How can I do it?
Upvotes: 0
Views: 2477
Reputation: 2022
try this:
my_mat <- matrix(1:20, ncol = 2)
my_seq <- c(3, 5, 6, 8)
for(i in my_seq) {
print(my_mat[i, ])
}
Upvotes: 2