[R] Extracting the longest entry

chumpmonkey@hushmail.com chumpmonkey at hushmail.com
Wed May 7 18:46:50 CEST 2003


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







Free, ultra-private instant messaging with Hush Messenger




More information about the R-help mailing list