p-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of peter dalgaard
Sent: Tuesday, April 26, 2011 8:13 AM
To: David Winsemius
Cc: r-help@r-project.org
Subject: Re: [R] Second largest element from each matrix row
On Apr 26, 2011, at 14:36 , David Winsemius wrote:
On Apr 26, 2
@r-project.org] On Behalf Of William Dunlap
> Sent: Tuesday, April 26, 2011 9:11 AM
> To: peter dalgaard; David Winsemius
> Cc: r-help@r-project.org
> Subject: Re: [R] Second largest element from each matrix row
>
> A different approach is to use order() to sort
> first
iginal Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of peter dalgaard
> Sent: Tuesday, April 26, 2011 8:13 AM
> To: David Winsemius
> Cc: r-help@r-project.org
> Subject: Re: [R] Second largest element from each matrix row
&g
On Apr 26, 2011, at 14:36 , David Winsemius wrote:
>
> On Apr 26, 2011, at 8:01 AM, Lars Bishop wrote:
>
>> Hi,
>>
>> I need to extract the second largest element from each row of a
>> matrix. Below is my solution, but I think there should be a more efficient
>> way to accomplish the same, or
Thanks a lot to all of you!
On Tue, Apr 26, 2011 at 10:34 AM, Peter Ehlers wrote:
> On 2011-04-26 05:26, Dimitris Rizopoulos wrote:
>
>> one way is the following:
>>
>> a<- matrix(rnorm(9), 3 ,3)
>>
>> aa<- a[order(row(a), -a)]
>> matrix(aa, nrow(a), byrow = TRUE)[, 2]
>>
>
> That's clever, Dmit
On 2011-04-26 05:26, Dimitris Rizopoulos wrote:
one way is the following:
a<- matrix(rnorm(9), 3 ,3)
aa<- a[order(row(a), -a)]
matrix(aa, nrow(a), byrow = TRUE)[, 2]
That's clever, Dmitris. And very fast!
Lars: my apologies; I didn't read your request
carefully. You asked for more _efficient
On Apr 26, 2011, at 8:01 AM, Lars Bishop wrote:
Hi,
I need to extract the second largest element from each row of a
matrix. Below is my solution, but I think there should be a more
efficient
way to accomplish the same, or not?
set.seed(1)
a <- matrix(rnorm(9), 3 ,3)
sec.large <- as.vector
On 2011-04-26 05:01, Lars Bishop wrote:
Hi,
I need to extract the second largest element from each row of a
matrix. Below is my solution, but I think there should be a more efficient
way to accomplish the same, or not?
set.seed(1)
a<- matrix(rnorm(9), 3 ,3)
sec.large<- as.vector(apply(a,
would this work (shorter)?
apply(a, 1, function(x) x[order(x)[2]])
On Tue, Apr 26, 2011 at 5:31 PM, Lars Bishop wrote:
> Hi,
>
> I need to extract the second largest element from each row of a
> matrix. Below is my solution, but I think there should be a more efficient
> way to accomplish the s
one way is the following:
a <- matrix(rnorm(9), 3 ,3)
aa <- a[order(row(a), -a)]
matrix(aa, nrow(a), byrow = TRUE)[, 2]
I hope it helps.
Best,
Dimitris
On 4/26/2011 2:01 PM, Lars Bishop wrote:
Hi,
I need to extract the second largest element from each row of a
matrix. Below is my solution
Hi,
I need to extract the second largest element from each row of a
matrix. Below is my solution, but I think there should be a more efficient
way to accomplish the same, or not?
set.seed(1)
a <- matrix(rnorm(9), 3 ,3)
sec.large <- as.vector(apply(a, 1, order, decreasing=T)[2,])
ans <- sappl
11 matches
Mail list logo