[R] accessing a data frame with row names

Petr PIKAL petr.pikal at precheza.cz
Tue Jun 1 10:36:00 CEST 2010


Hi

r-help-bounces at r-project.org napsal dne 01.06.2010 10:20:35:

> On 31/05/2010, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> > Use read.csv or read.table(..., sep = ",").  Also note that if you
> > delete the first comma of the header (as in the second example below)
> > you won't have to specify row.names since it can figure it out from
> > the fact that there is one fewer column name than data fields.
> >
> >> Lines <- ",column1,column2
> > + row1,0.1,0.2
> > + row2,0.3,0.4"
> >>
> >> read.csv(textConnection(Lines), row.names = 1)
> >      column1 column2
> > row1     0.1     0.2
> > row2     0.3     0.4
> 
> Thank you. When I enter the command:
> 
> max(dataframe[,2])
> 
> The response is:
> 
> [1] 0.4
> 
> But I want to receive the row name, i.e.:
> 
> [1] row2 0.4

It seems that you probably shall consult

?which with parameter arr.ind=T

which(dataframe==max(dataframe), arr.ind=T)

Regards
Petr


> 
> Is this possible?
> 
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list