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:
colnames(df)[2]
Michael
On Thu, Feb 2, 2012 at 10:31 AM, ikuzar raz...@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
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
Sorry, it was not clear:
my program have to return column name corresponding to a value, for example
'b' (so, the corresponding column is c1)
How to retrieve c1 ?
Thanks
--
View this message in context:
I'd use something like
which(df == b, arr.ind = TRUE)
which, gives the column number in the second spot; this gives you
colnames(df)[which(df == b, arr.ind = TRUE)[2]]
Michael
On Thu, Feb 2, 2012 at 11:00 AM, ikuzar raz...@hotmail.fr wrote:
Sorry, it was not clear:
my program have to
5 matches
Mail list logo