[R] Picking Part of Large R Object

Sparks, John James jspark4 at uic.edu
Sun Aug 1 07:21:35 CEST 2010


Dear All,

I have imported an HTML document to R (called tables) and wish to select
certain pieces of it for processing.  The first few lines of the object
appear as follows:

> tables
[[1]]
<table id="fs-table" class="gf-table rgt">
  <thead>
    <tr><th class="lm lft nwp">
In Millions of USD (except for per share items)
</th>
<th class="rgt">
3 months ending 2010-06-30
</th>
<th class="rgt">
3 months ending 2010-03-31
</th>
<th class="rgt">
3 months ending 2009-12-31
</th>
<th class="rgt">
3 months ending 2009-09-30
</th>
<th class="rgt rm">
3 months ending 2009-06-30
</th>
</tr>
  </thead>
  <tbody>
    <!-- 1 row for one coaitem -->
    <tr><td class="lft lm">Revenue
</td>
<td class="r">16,039.00</td>
<td class="r">14,503.00</td>
<td class="r">19,022.00</td>
<td class="r">12,920.00</td>
<td class="r rm">13,099.00</td>
</tr>
....

The next major partition of the object is:

[[2]]
<table id="fs-table" class="gf-table rgt">
  <thead>
    <tr><th class="lm lft nwp">
In Millions of USD (except for per share items)
</th>
<th class="rgt">
12 months ending 2010-06-30
</th>
<th class="rgt">
12 months ending 2009-06-30
</th>
<th class="rgt">
12 months ending 2008-06-30
</th>
<th class="rgt rm">
12 months ending 2007-06-30
</th>
</tr>
  </thead>
  <tbody>
    <!-- 1 row for one coaitem -->
    <tr><td class="lft lm">Revenue
</td>
<td class="r">62,484.00</td>
<td class="r">58,437.00</td>
<td class="r">60,420.00</td>
<td class="r rm">51,122.00</td>
</tr>
    <tr><td class="lft lm">Other Revenue, Total
</td>
<td class="r">-</td>
<td class="r">-</td>
<td class="r">-</td>
<td class="r rm">-</td>
</tr>
    <tr class="hilite"><td class="lft lm bld">Total Revenue
</td>
<td class="r bld">62,484.00</td>
<td class="r bld">58,437.00</td>
<td class="r bld">60,420.00</td>
<td class="r bld rm">51,122.00</td>
</tr>
    <tr><td class="lft lm">Cost of Revenue, Total
</td>
<td class="r">12,395.00</td>
<td class="r">12,155.00</td>
<td class="r">11,598.00</td>
<td class="r rm">10,693.00</td>


How can I specify the part of the R object denoted by [[1]] and put it
into a new object for processing.  As in table1<-...

I have tried many variations of [[1]], c[1], etc. but haven't had any
luck.  Guidance would be much appreciated.

--John Sparks, Ph.D.



More information about the R-help mailing list