My datatable has 19 columns with the first column all filled with timestamps in milliseconds:
18491
18591
18691
…
Randomly in the timestamp column, the time will change from +100 increments to +50 increments:
20291
20341
20391
20441
…
and back again, multiple times.
The other columns have different values of data spread about at different frequencies such as 1 Hz, 5Hz, 10Hz with double.NaN in between the values.
What is the best way to average these columns to 1Hz data while neglecting the NaN cells and creating a new datatable with only 1Hz data and no blanks?
i.e.:
From:
Time Col1 Col2 Col3 Col4 Col5
18491 4.0 2.2 NaN 1.0 NaN
18591 NaN NaN 1.0 1.0 NaN
18691 NaN 3.2 NaN 2.0 NaN
18791 NaN NaN NaN 3.0 NaN
18891 NaN 4.4 NaN 1.0 NaN
18991 NaN NaN NaN 4.0 NaN
19091 NaN 1.4 6.0 4.0 NaN
19191 NaN NaN NaN 3.0 NaN
19291 NaN 3.2 NaN 2.0 NaN
19341 NaN NaN NaN NaN 2.0
19391 NaN NaN NaN 3.0 NaN
19441 6.0 3.4 NaN NaN 1.0
19491 NaN NaN NaN 2.0 NaN
19541 NaN NaN NaN NaN 3.0
19591 NaN NaN 3.0 4.0 NaN
19641 NaN 5.2 NaN NaN 1.0
19691 NaN NaN NaN 2.0 NaN
19791 NaN NaN NaN 1.0 NaN
19891 NaN 4.1 NaN 0.0 NaN
19991 NaN NaN NaN 2.0 NaN
20091 NaN 2.2 4.0 1.0 NaN
20191 NaN NaN NaN 1.0 NaN
20291 NaN 5.1 NaN 1.0 NaN
20391 NaN NaN NaN 1.0 NaN
20491 5.0 3.3 NaN 2.0 NaN
To:
Time Col1 Col2 Col3 Col4 Col5
18491 4.0 2.2 NaN 1.0 NaN
19491 6.0 3.21 3.5 2.5 1.5
20491 5.0 3.98 3.5 1.5 2.0
Any help is appreciated, I’m still new to C# and datatables so thank you all in advance!
You will need to modify the rounding logic to match your requirements for how you decides 491 vs 441 as the round to number. Probably some combination of floor instead of round, and then + 491.