Extract names of the levels of a factor
<p>I'm trying to read a huge matrix (2.8gb) in R, thus, so far, the best I have found is</p>

<pre><code> require(data.table)

 DT&lt;-fread("bigmatrix.csv")
</code></pre>

<p>of which I know almost nothing!</p>

<p>After this I'm able to tell you that this matrix has 3 columns and 50 milion rows.</p>

<p>Each row is of the type</p>

<pre><code>             object1                       object 2           distance
 1: Kho.CENTRAL_KHOISAN.GWI           Kho.CENTRAL_KHOISAN.GWI 0.0000000
 2: Kho.CENTRAL_KHOISAN.GWI         Kho.CENTRAL_KHOISAN.GXANA 0.2195843  
 3: Kho.CENTRAL_KHOISAN.GWI Kho.CENTRAL_KHOISAN.KHOEKHOEGOWAB 0.6749363
 4: Kho.CENTRAL_KHOISAN.GWI          Kho.CENTRAL_KHOISAN.KHWE 0.6089206
 5: Kho.CENTRAL_KHOISAN.GWI        Kho.CENTRAL_KHOISAN.KORANA 0.7163111
 6: Kho.CENTRAL_KHOISAN.GWI         Kho.CENTRAL_KHOISAN.KWADI 0.8017179
</code></pre>

<p>So it's comparing distances of 2 objects pairwise for approximately 6900 objects</p>

<p>Now comes my problem:</p>

<p>I want to excract the pairwise comparison of just 41 objects. However I don't know how the guy who gave me this dataset has called these 41 objects!! </p>

<p>So my solution would be to find the levels of DT$object1, write them in a file and then scan them to find the 41 I need, how can I do it?</p>

<p>I tried</p>

<pre><code>foo&lt;-factor(DT$object1)
</code></pre>

<p>So when I call</p>

<pre><code>foo

....

6895 Levels: AA.BEJA.BEJA AA.BEJA.BEJA_2 AA.BERBER.AWJILAH ... Zun.ZUNI.ZUNI
</code></pre>

<p>but </p>

<pre><code>foo$Levels
</code></pre>

<p>gives me an error!</p>

<p>I'm sure there is a smarter way than what I would do in C++ (i.e. loop over each row, insert the name of Object 1 in a vector of strings only if it's not present yet), but how do I do it?</p>

<hr>

<p><strong>EDIT:</strong> Now another question arose:</p>

<p>I have identified the 41 objects that I need, how do I exctract from the data.table the rows that are relevant to me?</p>

<p>I can store the names of the objects in a data frame or a vector</p>