I would like to transform/modify the content of dataframe. Basically I have a dataframe like below:
bins pval
1 2L:1:150 0.9224217
2 2L:151:300 0.9478824
3 2L:301:450 0.9671139
4 2L:451:600 0.9280847
5 2L:601:750 0.9698584
6 2L:751:900 0.9725379
And I would like to transform/modify into another dataframe like this, where I split the content of my “bins” column (first row) into 150 rows containing the same values. And so on for the second row.
chr pos pval
1 2L 1 0.9224217
2 2L 2 0.9224217
3 2L 3 0.9224217
4 2L 4 0.9224217
5 2L 5 0.9224217
...
150 2L 150 0.9224217
151 2L 151 0.9478824
152 2L 152 0.9478824
153 2L 153 0.9478824
etc...
Any help much appreciated,
Ben
The quick answer which may be, I fear, too specific and may need generalization. Assume the first dataframe is named “df1”:
data.frame(chr=”2L”, pos=1:(150*NROW(df1)), pval=rep(df1$pval, each=150) )
Argument recycling should make the “chr” long enough without a rep function.
Edit in reply to comment. If the repeat length is always 150 then the fix is easy: