[R] Getting multiple matrix-values using a single command
cbeleites at units.it
Fri Mar 12 19:57:29 CET 2010
use a matrix of n x 2 to index. For details: sec. 5.3 "Index matrices" in the
Nils Rüfenacht wrote:
> Dear all!
> I'm trying to get multiple values from a matrix by using a single command.
> Given a matrix A
> A <- matrix(seq(1,9),nrow=3,ncol=3)
> How can I get e.g. the values A[1,2] = 4 and A[3,3] = 9 with a single
> command and without using any loop? My first idea was to generate a row-
> and a column vector for the indices, i.e. c(1,3) indicating row number 1
> (for A[1,2]) and row number 3 (for A[3,3]) and similar for
> column-indices. Then I've tried to call
> but instead of 4 , 9 the result is
> [,1] [,2]
> [1,] 4 7
> [2,] 6 9
> Any suggestions?
> Regards, Nils
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
phone: +39 0 40 5 58-37 68
email: cbeleites at units.it
More information about the R-help