Skip to content
Back to formatted view

Raw Message

Message-ID: <3EB940A0.9040208@statistik.uni-dortmund.de>
Date: 2003-05-07T17:21:36Z
From: Uwe Ligges
Subject: Extracting the longest entry
In-Reply-To: <200305071646.h47Gkocj068526@mailserver2.hushmail.com>

chumpmonkey at hushmail.com wrote:
> I have a matrix with NAs and want to extract the longest column.
> 
> 
>>is.matrix(foo)
> 
> [1] TRUE
> 
>>dim(foo)
> 
> [1] 2000   75
> 
>>GetLength <- function(x) {length(na.omit(x))}
>>junk <- apply(foo, 2, GetLength)
>>junk
> 
>  [1] 1004  512  432  523  691  396  607  838
>  [9]  730  389  388  445  609  333  637 1024
> [17] 1163  823  718  466  799  459  701  833
> [25]  456  549  376  728  539  384  348  708
> [33]  516  439  667 1115  711 1105  469  864
> [41]  748  788  394  426  338  532  742  479
> [49]  570  503  784  302  746  507  532  702
> [57]  562  693  592  850  491  789  362  487
> [65]  679  617  513  752  690  597  992  496
> [73]  688  579  712
> 
> 
> Now I want to extract the greatest entry (i.e., 17). This is where I'm
> stuck and feel foolish. This is clearly trivial. Help!
> 
> CM

which.max(junk)

Uwe Ligges