s-news
[Top] [All Lists]

Extracting Elements from a matrix

To: <s-news@lists.biostat.wustl.edu>
Subject: Extracting Elements from a matrix
From: "Ilouga, Pierre" <Pierre.Ilouga@evotec.com>
Date: Wed, 7 Nov 2007 18:11:36 +0100
Thread-index: AcghYUBt53Q3oqr2RyWEATzTh8bRug==
Thread-topic: Extracting Elements from a matrix

Dear Splus experts,

Does anyone has an idea how to extract some elements from a matrix in an EFFICIENT way? The following example clarifies  my question.

Given a  5x3 matrix  mat <- matrix(1:15, nrow=5, byrow=F)  and a length 5 -vector  of positions  pos <- c(2, 1, 3, 3, 1), the goal is to extract the vector c(6, 2, 13, 14, 5) which  corresponds to the column pos[j]  (j in 1:3) and row i  ( i in 1:5) without using for-loops and other memory consuming functions.

Ive solve it via lists. However the slowness of the command executions doesnt make it useful for  monte carlo simulation.

Thanks in advance.

PI

S-PLUS : Copyright (c) 1988, 2002 Insightful Corp.

S : Copyright Lucent Technologies, Inc.

Version 6.1.2 Release 2 for Linux 2.2.12 : 2002

Working data will be in .Data


Dr. Pierre Ilouga

Screening Operations/Discovery Informatics

EVOTEC AG

Schnackenburgallee 114

22525 Hamburg

Germany

pierre.ilouga@evotec.com

www.evotec.com

                   

Evotec AG Hamburg. Amtsgericht Hamburg HRB 68223
Vorstand: Jörn Aldag (Vorsitzender)
Aufsichtsratsvorsitzender: Prof. Dr. Dr. h.c. mult. Heinz Riesenhuber

<Prev in Thread] Current Thread [Next in Thread>