rm167
rm167

Reputation: 1247

For loop over selected rows

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

Answers (1)

Miha Trošt
Miha Trošt

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

Related Questions