Re: [R] numeric index of a matrix column name ?

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Sat 29 Oct 2005 - 01:00:19 EST

probably you need

match(colname0, colnames(M))

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm



> Dear All,
>
> I have written the following small code in order to return
> the numeric index of a given matrix column ascii name.
> It works, but there is perhaps/probably a predefined function
> which does that ?
> If yes, thanks for pointing me to it.
>
> # input : a matrix M and a column ascii name
> # output : the numeric index of the column
> colnameindex = function(M , colname0)
> {
> colsnames = names(M[1,]);
> theindex = which(colsnames==colname0);
> return(theindex);
> }
>
> Thanks
> Vincent
>
> ______________________________________________
> 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
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



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 Received on Sat Oct 29 01:19:39 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:52 EST