w*****1 发帖数: 473 | 1 【 以下文字转载自 Statistics 讨论区 】
发信人: wz99331 (dotti), 信区: Statistics
标 题: ask for help for R programming
发信站: BBS 未名空间站 (Thu Oct 16 15:25:16 2014, 美东)
I need to transpose a file to example.txt
the final dataset should be sorted by chr first then by position. Could
anyone help me to write the R code? Thank you very much!
raw data:
snp Chr pos Sample.ID Allele1 Allele2
rs6269442 1 1.614 517 A B
rs13475701 1 1.744 517 A B
rs13475706 1 1.889 517 A B
rs3684358 1 2.06 517 A B
rs13475729 1 3.749 517 A B
rs3671256 1 5.009 517 A B
rs13475750 1 6.153 517 A B
rs6404446 1 6.442 517 A B
rs31949292 1 8.486 517 A B
rs6173215 1 8.692 517 A B
rs31917015 1 10.425 517 A B
rs6166266 1 10.731 517 A B
rs3677683 1 10.932 517 A B
rs3695988 1 11.345 517 A B
rs4137502 1 11.461 517 A B
.
.
.
example.txt
snp chr pos sampel.id1 sample.id2 .........
rs6269442 1 1.614 AB AB
rs13475701 1 1.744 AA AB
rs13475706 1 1.889 AA AB
rs3684358 1 2.06 AB BB
rs13475729 1 3.749 AB BB
rs3671256 1 5.009 AB BB
rs13475750 1 6.153 AB AB
rs6404446 1 6.442 AB AB
rs31949292 1 8.486 AB AB
rs6173215 1 8.692 AB AB
rs31917015 1 10.425 AB AB
rs6166266 1 10.731 AB AB
rs3677683 1 10.932 AB AB
rs3695988 1 11.345 AB AB
rs4137502 1 11.461 AB AB
.
.
. | k*e 发帖数: 238 | 2 ordered = raw[order(raw$Chr, raw$pos),]
【在 w*****1 的大作中提到】 : 【 以下文字转载自 Statistics 讨论区 】 : 发信人: wz99331 (dotti), 信区: Statistics : 标 题: ask for help for R programming : 发信站: BBS 未名空间站 (Thu Oct 16 15:25:16 2014, 美东) : I need to transpose a file to example.txt : the final dataset should be sorted by chr first then by position. Could : anyone help me to write the R code? Thank you very much! : raw data: : snp Chr pos Sample.ID Allele1 Allele2 : rs6269442 1 1.614 517 A B
| w*****1 发帖数: 473 | 3 this is only to order the data, did not transpose the snp id so that each
column is for one sample id, currently each sample has many snps. | w*****1 发帖数: 473 | 4 there are about 1000 sample ids, I only list the first sample id. | P*****6 发帖数: 273 | 5 用个loop 不就行了。你又不追求速度
【在 w*****1 的大作中提到】 : there are about 1000 sample ids, I only list the first sample id.
|
|