Re: [R] Access Rows in a Data Frame by Row Name

From: Berton Gunter <gunter.berton_at_gene.com>
Date: Wed 13 Sep 2006 - 19:11:39 GMT


The answer is yes, you can access rows of a data.frame by rowname in the same way as columns, which you could have found by merely trying it. Don't overlook the value of a little experimentation as the fastest way to an answer.

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Tony Plate
> Sent: Wednesday, September 13, 2006 11:02 AM
> To: Michael Gormley
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] Access Rows in a Data Frame by Row Name
>
> Matrix-style indexing works for both columns and rows of data frames.
>
> E.g.:
> > x <- data.frame(a=1:5, b=6:10, d=11:15)
> > x
> a b d
> 1 1 6 11
> 2 2 7 12
> 3 3 8 13
> 4 4 9 14
> 5 5 10 15
> > x[2:4,c(1,3)]
> a d
> 2 2 12
> 3 3 13
> 4 4 14
> >
>
> Time spend reading the help document "An Introduction to R" will
> probably be well worth it. The relevant sections are "5 Arrays and
> matrices", and "6.3 Data frames".
>
> -- Tony Plate
>
> Michael Gormley wrote:
> > I have created a data frame using the read.table command.
> I want to be able to access the rows by the row name, or a
> vector of row names. I know that you can access columns by
> using the data.frame.name$col.name. Is there a way to access
> row names in a similar manner?
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch 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.
> >
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>



R-help@stat.math.ethz.ch 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. Received on Thu Sep 14 05:17:45 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 14 Sep 2006 - 05:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.