| To: | "Ilouga, Pierre" <Pierre.Ilouga@evotec.com>, s-news@lists.biostat.wustl.edu |
|---|---|
| Subject: | Re: Extracting Elements from a matrix |
| From: | "Greg Snow" <Greg.Snow@intermountainmail.org> |
| Date: | Wed, 7 Nov 2007 12:05:02 -0700 |
| In-reply-to: | <872D12160996E34584346FAF67F200E8027862@ge-ham-sma01.germany.evotecoai.com> |
| References: | <872D12160996E34584346FAF67F200E8027862@ge-ham-sma01.germany.evotecoai.com> |
| Thread-index: | AcghYUBt53Q3oqr2RyWEATzTh8bRugAD7u8w |
| Thread-topic: | [S] Extracting Elements from a matrix |
|
Is this what you are looking for?
> mat <- matrix(1:15, nrow=5, byrow=F)
> mat [,1] [,2] [,3] [1,] 1 6 11 [2,] 2 7 12 [3,] 3 8 13 [4,] 4 9 14 [5,] 5 10 15 > pos <- c(2, 1, 3, 3, 1) > mat[ cbind(1:5, pos) ] [1] 6 2 13 14 5 The key is to subscript using a matrix (not multiple
vectors) with the 1st column representing all the rows and the 2nd the columns
from those rows.
Hope this helps,
--
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: Extracting Elements from a matrix, Biggerstaff, Brad J. \(CDC/CCID/NCZVED\) |
|---|---|
| Next by Date: | Re: Extracting Elements from a matrix, Biggerstaff, Brad J. \(CDC/CCID/NCZVED\) |
| Previous by Thread: | Re: Extracting Elements from a matrix, Biggerstaff, Brad J. \(CDC/CCID/NCZVED\) |
| Next by Thread: | Re: Extracting Elements from a matrix, Richard A. Becker |
| Indexes: | [Date] [Thread] [Top] [All Lists] |