'How do I get the first five columns of a dataframe in a txt file?
I want to save the first five columns in log2ratios.txt as output.txt.
awk -v b=1 -v e=5 'BEGIN{FS=OFS=","} {for (i=b;i<=e;i++) printf "%s%s", $i, (i<e ? OFS : ORS)}' log2ratios.txt >> output.txt
I've also tried:
cut -d, -f1-5 log2ratios.txt >> output.txt
Current output (snapshot):
ProbeSetName Chromosome Position Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio,,,,
1 CN_473963 1 51586 -0.574911 -0.409836 0.072711 -0.345886 -0.441539 -0.11781 -0.426072 -0.611897 -0.060026,,,,
2 CN_473964 1 51659 -0.256262 -0.214604 -0.153238 -0.051997 -0.472509 -0.156168 -0.263254 -0.326569 -0.339877,,,,
Desired output:
output.txt should contain the following information.
> as.data.frame( r[,1:5], drop=false)
ProbeSetName Chromosome Position Log2Ratio m.Log2Ratio
1 CN_473963 1 51586 -0.574911 -0.409836
2 CN_473964 1 51659 -0.256262 -0.214604
3 CN_473965 1 51674 -0.030027 -0.322802
4 CN_473981 1 52771 -0.399400 -0.657841
5 CN_473982 1 52788 -0.118232 -0.840977
6 CN_497981 1 62627 0.150264 -0.244675
7 CN_502615 1 75787 -0.669798 -1.320492
8 CN_502613 1 75849 -0.125760 -0.145890
9 CN_502614 1 76175 -1.654274 -2.419629
10 CN_502616 1 76192 -2.385214 -2.417917
11 CN_502843 1 88453 -0.591260 -0.501315
12 CN_466171 1 218557 -0.374847 -0.367135
13 CN_468414 1 218926 0.797292 0.818930
14 CN_468412 1 219009 0.356342 0.273622
15 CN_468413 1 219024 0.164000 -0.111701
16 CN_470565 1 219470 0.721352 0.399291
17 CN_468424 1 225521 -0.190690 -0.077926
18 CN_468425 1 225579 -0.667092 -0.212682
19 CN_460512 1 346294 -0.524201 -0.516528
20 CN_460513 1 346393 0.258182 0.013902
21 SNP_A-8575125 1 554484 0.326082 0.361037
22 SNP_A-8575115 1 554636 0.021981 -0.249903
23 SNP_A-8575371 1 557616 0.269811 -0.039262
[ reached 'max' / getOption("max.print") -- omitted 1813241 rows ]
data:
head log2ratios.txt
ProbeSetName Chromosome Position Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio m$Log2Ratio
1 CN_473963 1 51586 -0.574911 -0.409836 0.072711 -0.345886 -0.441539 -0.11781 -0.426072 -0.611897 -0.060026
2 CN_473964 1 51659 -0.256262 -0.214604 -0.153238 -0.051997 -0.472509 -0.156168 -0.263254 -0.326569 -0.339877
3 CN_473965 1 51674 -0.030027 -0.322802 -0.59208 -0.305452 -0.092585 -0.227589 -0.18488 -0.339897 -0.211489
4 CN_473981 1 52771 -0.3994 -0.657841 -0.537569 -0.695869 -0.27919 -0.236683 -0.428801 -0.49314 -0.364471
5 CN_473982 1 52788 -0.118232 -0.840977 -0.329929 -0.448378 -0.308569 -0.315758 -0.511238 -0.518504 -0.372665
6 CN_497981 1 62627 0.150264 -0.244675 -0.127441 0.042639 -0.111781 0.061487 -0.045214 -0.19797 -0.088062
7 CN_502615 1 75787 -0.669798 -1.320492 -0.836021 -0.702558 -0.427371 -0.454593 -0.721925 -0.191238 -0.513743
8 CN_502613 1 75849 -0.12576 -0.14589 -0.298104 -0.136768 -0.272062 0.214592 -0.021858 -0.07202 -0.365969
9 CN_502614 1 76175 -1.654274 -2.419629 -1.918768 -1.56881 -1.65782 -0.525656 -0.873399 -0.889187 -0.670121
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
