Skip to content
Prev 367352 / 398502 Next

How to use apply() to fill matrix by rows or columns?

The apply function is one of many alienate ways to write a loop. It is not appreciably more efficient in cpu time than a for loop.

Your example creates the numbers in the loop... does your actual data get created in a loop? If so then your original code should be perfectly serviceable. If not then there might be a better way to do this, but you would have to expand your example to illustrate how the data comes to you in order to suggest alternatives.

Also post using plain text to prevent your code from being mangled on its way to us.