tag:blogger.com,1999:blog-6232819486261696035.post5881866650377753762..comments2023-09-25T09:01:44.323-05:00Comments on Getting Genetics Done: R: Given column name in a Data Frame, Get the IndexStephen Turnerhttp://www.blogger.com/profile/06656711316726116187noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-6232819486261696035.post-32362946356422952812011-04-27T10:39:37.544-05:002011-04-27T10:39:37.544-05:00brilliant, neat answer. thanks!brilliant, neat answer. thanks!tomhttps://www.blogger.com/profile/14090701350546871378noreply@blogger.comtag:blogger.com,1999:blog-6232819486261696035.post-21020252661607672112011-02-18T07:29:46.356-06:002011-02-18T07:29:46.356-06:00haha I totally spent a good 1/2 hr with this same ...haha I totally spent a good 1/2 hr with this same question yesterday morning. Just saw the repost to R-bloggers<br /><br />Thanks for both versionsm @ random musingshttps://www.blogger.com/profile/18050161494826227735noreply@blogger.comtag:blogger.com,1999:blog-6232819486261696035.post-71231010570492972872011-02-17T13:55:05.140-06:002011-02-17T13:55:05.140-06:00Following Alex, note that if you had specified
...Following Alex, note that if you had specified<br /> <br />>mycols <-c("Species","Sepal.Width")<br /><br />then your first answer would be wrong (if you cared about retaining order, which I usually do). match() would give the right answer.<br /><br />Also, match has the potential to be faster if you are doing a lot of comparisons.Anonymoushttps://www.blogger.com/profile/14706878044156810457noreply@blogger.comtag:blogger.com,1999:blog-6232819486261696035.post-1021147848793715382011-02-17T13:08:35.763-06:002011-02-17T13:08:35.763-06:00The 'match' function is even easier for th...The 'match' function is even easier for this. It returns indices for the first vector argument's matches in the second one.<br /><br />> match(mycols, colnames(iris))<br />[1] 2 5Alexhttps://www.blogger.com/profile/05446127954359543819noreply@blogger.com