Name of a column

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Name of a column

David Hajage
Hello,

My problem is quite simply, but I didn't find any solution...

I have a vector :

> truc
   longueur30 longueur40 longueur50 longueur60 longueur70 longueur80
longueur90
34      FALSE      FALSE      FALSE      FALSE       TRUE      FALSE
FALSE

I would like to have the name of the column where there is "TRUE".

> colnames(truc)
[1] "longueur30" "longueur40" "longueur50" "longueur60" "longueur70"
[6] "longueur80" "longueur90"

> truc[truc == T]
[1] TRUE

> colnames(truc[truc == T])
NULL

How can I do it ?

Thank you for your help.

--
David

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Name of a column

Chuck Cleland
X <- as.logical(rep(c(0,1), each=13))

names(X) <- LETTERS

which(X)
  N  O  P  Q  R  S  T  U  V  W  X  Y  Z
14 15 16 17 18 19 20 21 22 23 24 25 26

names(which(X))
  [1] "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"

?which

David Hajage wrote:

> Hello,
>
> My problem is quite simply, but I didn't find any solution...
>
> I have a vector :
>
>> truc
>    longueur30 longueur40 longueur50 longueur60 longueur70 longueur80
> longueur90
> 34      FALSE      FALSE      FALSE      FALSE       TRUE      FALSE
> FALSE
>
> I would like to have the name of the column where there is "TRUE".
>
>> colnames(truc)
> [1] "longueur30" "longueur40" "longueur50" "longueur60" "longueur70"
> [6] "longueur80" "longueur90"
>
>> truc[truc == T]
> [1] TRUE
>
>> colnames(truc[truc == T])
> NULL
>
> How can I do it ?
>
> Thank you for your help.
>

--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Name of a column

David Hugh-Jones-3
In reply to this post by David Hajage
1. You don't need to say  truc==T. truc is already a logical vector.

2. colnames are just another vector, so do

colnames(truc)[truc]

Dave

On 15/06/06, David Hajage <[hidden email]> wrote:

> Hello,
>
> My problem is quite simply, but I didn't find any solution...
>
> I have a vector :
>
> > truc
>    longueur30 longueur40 longueur50 longueur60 longueur70 longueur80
> longueur90
> 34      FALSE      FALSE      FALSE      FALSE       TRUE      FALSE
> FALSE
>
> I would like to have the name of the column where there is "TRUE".
>
> > colnames(truc)
> [1] "longueur30" "longueur40" "longueur50" "longueur60" "longueur70"
> [6] "longueur80" "longueur90"
>
> > truc[truc == T]
> [1] TRUE
>
> > colnames(truc[truc == T])
> NULL
>
> How can I do it ?
>
> Thank you for your help.
>
> --
> David
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html