Relative Content

Tag Archive for rdata.table

Transforming a data.table in R and assigning Scores Based on Start and End Positions

I have a data.table df in R with four columns: id, start, end, score. The start and end range from 1 to 10 and id might have duplicates. I would like to transform this data.table into a new matrix B where each row corresponds to an id, and has 10 columns corresponding to each position from 1 to 10. If a position is within the start and end in df for a particular id, the corresponding cell in B should be the score, otherwise it should be 0.

R data.table explode multiple rows at once

Similar to this post, I have some columns with comma separated values and I wish to explode them to additional rows with shared by columns (data below). In this case they are aligned, so the comma ordering is preserved. So the exploded version would be 51 total rows, where each column with a comma separated value is split (Model, Pathological Tau, Tau Enzymes).