Description Usage Arguments Details Value Examples

View source: R/sparse.extract.index.R

Computes a matrix index that extracts individual (i, j) elements. This differ from the standard extraction where all columns in rows `i`

and all rows in columns `j`

are extracted.

1 2 |

`i, j` |
the indices of the elements to extract. |

`nrow, ncol` |
the number of rows and colums of the index. currently, |

`byrow` |
only |

`na.rm` |
remove elements where i or j are |

`quiet` |
if |

Note that this is likely to NOT work on data frames.

the vector index for the matrix. Typically one would want to use this index to extract from a matrix, and a vector will be returned, regardless of the status of `drop`

.

1 2 3 4 5 | ```
m <- matrix(1:25, 5, 5)
m[1:5, 1:5] # Returns the whole matrix
m[sparse.extract.index(1:5, 1:5, nrow = 5)] # Returns the diagonal only
m[c(1, 3, 5), c(2, 4, 4)]
m[sparse.extract.index(c(1, 3, 5), c(2, 4, 4), nrow = 5)]
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.