Declaring an array of strings and integers
When you read in your two CSV files, you can explicitly declare the variable types for each column:

&gt; a &lt;- read.csv(..., colClasses=c("character"), ...)
&gt; b &lt;- read.csv(..., colClasses=c("character", "numeric", "numeric", ...), ...)


You could also investigate as.is or stringsAsFactors, although this can cause problems where there are duplicate strings. Using colClasses is more explicit. 

Read the help documentation in ?read.csv for a more complete explanation of these operators.

You can filter with the %in% operator in match:

&gt; strings_of_interest &lt;- as.vector(a$V1)
&gt; b.filtered &lt;- b[b$V1 %in% strings_of_interest,]


If I am reading your question correctly, perhaps you can then take b.filtered and turn that into the matrix you want.

Avoid use of for loops where you can. They can slow R down considerably. A good read on this subject is in the third chapter of Patrick Burns' The R Inferno.