# Create an HTML table from a matrix of numbers

**URL:** <https://talk.observablehq.com/t/create-an-html-table-from-a-matrix-of-numbers/1613>\
**Category:** Help\
**Created:** [January 28, 2019, 1:44am UTC](https://talk.observablehq.com/t/create-an-html-table-from-a-matrix-of-numbers/1613 "2019-01-28T01:44:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maliky](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/maliky/32/706_2.png) [@maliky](https://talk.observablehq.com/u/maliky)\
**Post date:** [January 28, 2019, 1:44am UTC](https://talk.observablehq.com/t/create-an-html-table-from-a-matrix-of-numbers/1613/1 "2019-01-28T01:44:33Z")

</div>

This is a question related to understanding [d3-selection’s documentation](https://github.com/d3/d3-selection/blob/master/README.md#selection_data).  
I try to run the following example in Observable

```
var matrix = [
  [11975, 5871, 8916, 2868],
  [1951, 10048, 2060, 6171],
  [8010, 16145, 8090, 8045],
  [1013, 990, 940, 6907]
];

var tr = d3.select("body")
  .append("table")
  .selectAll("tr")
  .data(matrix)
  .join("tr");

var td = tr.selectAll("td")
  .data(function(d) { return d; })
  .join("td")
    .text(function(d) { return d; });

```

I get that I should not use `d3.select("body")` but I thought replacing it by a

```
div = html`<div>`;
d3.select(div)...

```

would do the trick. It does not, sending me instead a `TypeError: d3.select(...).append(...).selectAll(...).data(...).join is not a function`

So why is `d3.select("body")` different from `d3.select(html`

')` beside the fact that the later will return a node without parent ?

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [January 28, 2019, 1:55am UTC](https://talk.observablehq.com/t/create-an-html-table-from-a-matrix-of-numbers/1613/2 "2019-01-28T01:55:54Z")

</div>

_selection_.join was added in d3-selection 1.4 and will be part of d3 5.8 which has not been released yet.
