[R] getting column's main

Jannis bt_jannis at yahoo.de
Mon Apr 19 17:59:05 CEST 2010


Try

col=max.col(data)


This should give you the index of the column with the max value. To get 
to the final result, combine this with

names(dataframe)[col]


 to get the name of the column with the maximum value.


HTH
Jannis

AuriDUL schrieb:
> Hello.
>
> I have data of potatoes production in EU during 1998-2009 from EuroStat
> where the first column consists of the names of EU countries, the following
> columns consists of appropriate data in each year.
>
> Let's say, I investigate Lithuania. For example, I have a row containing
> potatoes production in 1998, 1999, ..., 2009 in Lithuania. I can easily find
> the maximum value in this row but...
>
> ...but
>
> How could I print the year (the name of the column) where that maximum value
> of potaoes production in Lithuania exists? [if it's even possible.]
>
> I only have a code which can print a number of the column where that maximum
> value of Lithuania's potatoes production during 1998-2009 is.
>
> Thanks in advance.
>



More information about the R-help mailing list