[R] Simple column selection question- which and character lists

"Stefan Große" singularitaet at gmx.net
Mon Aug 31 18:58:36 CEST 2009


> I have a list of column names:
> >names.species.bio.18=c("Achimillb","Agrosmitb","Amorcaneb","Andrgerab","Ascltubeb","Elymcanab","Koelcrisb","Lespcapib","Liataspeb","Lupipereb","Monafistb","Panivirgb","Petapurpb","Poaprateb","Querellib","Quermacrb","Schiscopb","Sorgnutab")
> 
> I want to select the column numbers which correspond to these names in my
> data frame:
> >which(colnames(data)==names.species.bio.18)

How about:

num<-1:length(colnames(data))
num[colnames(data) %in% names.species.bio.18]

hth
Stefan

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser




More information about the R-help mailing list