[R] Simplest question ever...

2007-03-01 Thread yoooooo

Let's say i have

a = c(1, 4, 5)
b = c(2, 6, 7)

and i have matrix m, what's an efficient way of access
m[1, 2], m[4, 6], m[5, 7]
like of course m[a, b] = is not going to do, but what's an expression that
will allow me to have that list? 

Thanks!
-- 
View this message in context: 
http://www.nabble.com/Simplest-question-ever...-tf3329894.html#a9258932
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Simplest question ever...

2007-03-01 Thread Paul Lynch
I'm not sure this is the most efficient, but how about:
   diag(m[a,b])
?

On 3/1/07, yoo <[EMAIL PROTECTED]> wrote:
>
> Let's say i have
>
> a = c(1, 4, 5)
> b = c(2, 6, 7)
>
> and i have matrix m, what's an efficient way of access
> m[1, 2], m[4, 6], m[5, 7]
> like of course m[a, b] = is not going to do, but what's an expression that
> will allow me to have that list?
>
> Thanks!
> --
> View this message in context: 
> http://www.nabble.com/Simplest-question-ever...-tf3329894.html#a9258932
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Simplest question ever...

2007-03-01 Thread jim holtman
try:
> a = c(1, 4, 5)
> b = c(2, 6, 7)
> 
> m <- matrix(1:49,7,7)
> m[cbind(a,b)]   # 'array' indexing
[1]  8 39 47
> m
 [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]18   15   22   29   36   43
[2,]29   16   23   30   37   44
[3,]3   10   17   24   31   38   45
[4,]4   11   18   25   32   39   46
[5,]5   12   19   26   33   40   47
[6,]6   13   20   27   34   41   48
[7,]7   14   21   28   35   42   49
> 


 
Jim Holtman

"What is the problem you are trying to solve?"



- Original Message 
From: yoo <[EMAIL PROTECTED]>
To: r-help@stat.math.ethz.ch
Sent: Thursday, March 1, 2007 4:28:02 PM
Subject: [R] Simplest question ever...


Let's say i have

a = c(1, 4, 5)
b = c(2, 6, 7)

and i have matrix m, what's an efficient way of access
m[1, 2], m[4, 6], m[5, 7]
like of course m[a, b] = is not going to do, but what's an expression that
will allow me to have that list? 

Thanks!
-- 
View this message in context: 
http://www.nabble.com/Simplest-question-ever...-tf3329894.html#a9258932
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


 


Access over 1 million songs.

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Simplest question ever...

2007-03-01 Thread Ted Harding

On 01-Mar-07 Paul Lynch wrote:
> I'm not sure this is the most efficient, but how about:
>diag(m[a,b])
> ?

m[cbind(a,b)] will also do it:

m
 [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]  1.1  1.2  1.3  1.4  1.5  1.6  1.7
[2,]  2.1  2.2  2.3  2.4  2.5  2.6  2.7
[3,]  3.1  3.2  3.3  3.4  3.5  3.6  3.7
[4,]  4.1  4.2  4.3  4.4  4.5  4.6  4.7
[5,]  5.1  5.2  5.3  5.4  5.5  5.6  5.7

a <- c(1, 4, 5)
b <- c(2, 6, 7)

diag(m[a,b])
[1] 1.2 4.6 5.7

m[cbind(a,b)]
[1] 1.2 4.6 5.7

Ted.

> On 3/1/07, yoo <[EMAIL PROTECTED]> wrote:
>>
>> Let's say i have
>>
>> a = c(1, 4, 5)
>> b = c(2, 6, 7)
>>
>> and i have matrix m, what's an efficient way of access
>> m[1, 2], m[4, 6], m[5, 7]
>> like of course m[a, b] = is not going to do, but what's an expression
>> that
>> will allow me to have that list?
>>
>> Thanks!
>> --
>> View this message in context:
>> http://www.nabble.com/Simplest-question-ever...-tf3329894.html#a9258932
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 094 0861
Date: 01-Mar-07   Time: 23:44:22
-- XFMail --

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Simplest question ever...

2007-03-02 Thread chiya sharma
If I understand it correctly,
you mean to say

>a = c(1, 4, 5)
>b = c(2, 6, 7)

and
m<- rbind(a,b)
if you want to see a particular column
you can try

m[,1]

hope it helps,

-GS



On 3/2/07, yoo <[EMAIL PROTECTED]> wrote:
>
>
> Let's say i have
>
> a = c(1, 4, 5)
> b = c(2, 6, 7)
>
> and i have matrix m, what's an efficient way of access
> m[1, 2], m[4, 6], m[5, 7]
> like of course m[a, b] = is not going to do, but what's an expression that
> will allow me to have that list?
>
> Thanks!
> --
> View this message in context:
> http://www.nabble.com/Simplest-question-ever...-tf3329894.html#a9258932
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.