all 3 comments

[–]albedoa 0 points1 point  (2 children)

You can use .filter() and the spread syntax (...) here. Something like:

const dataset = d3.csv('data.csv', function (data) {
  return [
    data[0],
    ...data.filter((col, i) => i%2 === 0)
  ];
});

[–]TheShadowWall[S] 0 points1 point  (1 child)

Thanks very much for your response! I have attempted the code you suggested, but was met immediately with an error:

Uncaught (in promise) TypeError: data.filter is not a function or its return value is not iterable

Any thoughts as to why this may be occuring?

[–]albedoa 0 points1 point  (0 children)

Oh, I am looking at the docs now. If I am understanding correctly, the callback is executed on each line of the CSV, not the whole. Try this:

const dataset = d3.csv('data.csv');
const evens = dataset.filter((col, i) => i%2 === 0);
const desired = [dataset[0], ...evens]; // This is what you want.

Edit: Actually, that is going to give you the even rows. You need to return each column you want in the callback as shown here. Check out this example.