0

i have a tsv file with columns header. for eg: Name group town age One of the column is 'age'. Now i want to output complete row, where age is greater than or equal to 50.

I did the following:

if (file.name === 'participant.tsv'){
  for (var i = 0; i < rows.length; i++) {
    var row = rows[i];
    var values = row.split('\t');
    for (var j = 0; j < values.length; j++) {
      var headers = rows[0].split('\t');
      var ageIdColumn = headers.indexOf('age');
      var value = values[j]
      // age = Number(value)
        if (value == 89 || value > 89) {
            do so as so;
        };

But no luck.. can someone point out where i am making mistake?

The above script works when age is 89 but when age is above 89 it doesn't.

1 Answer 1

1

you can get ageIndex first (since its static) then loop through rows

when condition age >= 50 is true, push that row in to filteredRows

var filteredRows = [];
var headers = rows[0].split('\t');
var ageIndex = headers.indexOf('age');

if (file.name === 'participant.tsv') {
  rows.forEach(function(row) {
    var age = row.split('\t')[ageIndex];
    if (Number(age) >= 50) filteredRows.push(row);
  });
}

Sign up to request clarification or add additional context in comments.

1 Comment

apparently the above script is not working. when i print, age it gives me undefined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.