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

AllenL allen.larocque at gmail.com
Mon Aug 31 18:39:47 CEST 2009


Dear R-list,
Seems simple but have tried multiple approaches, no luck.

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)

Result:
+[1] 75 76
+Warning message:
+In cols == names.species.bio.18 :
+  longer object length is not a multiple of shorter object length

So I get the first two hits and then it trips an error message.

What is  >which doing? Why does it seem to have trouble with vectors of
characters? 
My goal is to output the column names/indices which correspond to the
columns NOT in the above list, but that is simple once I can find out what
they are.

Thanks!
-Allen

-- 
View this message in context: http://www.nabble.com/Simple-column-selection-question--which-and-character-lists-tp25226500p25226500.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list