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
numeric index of a matrix column name ?
3 messages · vincent@7d4.com, Dimitris Rizopoulos
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 ----- Original Message ----- From: <vincent at 7d4.com> To: <r-help at stat.math.ethz.ch> Sent: Friday, October 28, 2005 4:50 PM Subject: [R] numeric index of a matrix column name ?
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 at 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
Dimitris Rizopoulos a ??crit :
probably you need match(colname0, colnames(M)) I hope it helps. Best, Dimitris
yes. (why do simple ...) Thanks Dimitris. Have a good we. Vincent