Hi, I 'd like to know how to retrieve a column name of a data frame. For instance : df = data.frame(c1=c('a','b'),c2=c(1,2))> dfc1 c2 1 a 1 2 b 2 I would like to retrieve the column name which value is 2 (here, the column is c2) thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/How-to-retrieve-a-column-name-of-a-data-frame-tp4351764p4351764.html Sent from the R help mailing list archive at Nabble.com.
R. Michael Weylandt
2012-Feb-02 15:50 UTC
[R] How to retrieve a column name of a data frame
colnames(df)[2] Michael On Thu, Feb 2, 2012 at 10:31 AM, ikuzar <razuki at hotmail.fr> wrote:> Hi, > > I 'd like to know how to retrieve a column name of a data frame. For > instance : > > df = data.frame(c1=c('a','b'),c2=c(1,2)) >> df > ?c1 c2 > 1 ?a ?1 > 2 ?b ?2 > > I would like to retrieve the column name which value is 2 (here, the column > is c2) > > thanks for your help > > -- > View this message in context: http://r.789695.n4.nabble.com/How-to-retrieve-a-column-name-of-a-data-frame-tp4351764p4351764.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
> colnames( df )[2][1] "c2" On Thursday 02 February 2012 07:31:33 ikuzar wrote:> Hi, > > I 'd like to know how to retrieve a column name of a data frame. For > instance : > > df = data.frame(c1=c('a','b'),c2=c(1,2)) > > > df > > c1 c2 > 1 a 1 > 2 b 2 > > I would like to retrieve the column name which value is 2 (here, the column > is c2) > > thanks for your help > > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-retrieve-a-column-name-of-a-data-frame > -tp4351764p4351764.html Sent from the R help mailing list archive at > Nabble.com. > > ______________________________________________ > 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.