How to generate a pivotal table?
Clash Royale CLAN TAG#URR8PPP
I have a file which looks like this:
latitude Chr01 0.85
latitude Chr05 0.25
latitude Chr11 0.07
latitude Chr13_a 0.26
latitude Chr13_b 0.00
latitude Chr14_a 0.00
latitude Chr14_b 1
latitude Chr15 1
latitude Chr16_a 0.01
latitude Chr16_b 1
latitude Chr17 0.62
MCMT Chr01 1
MCMT Chr05 0.30
MCMT Chr11 0.018
MCMT Chr13_a 0.34
MCMT Chr13_b 0.00
MCMT Chr14_a 0.00
MCMT Chr14_b 1
MCMT Chr15 1
MCMT Chr16_a 0.00
MCMT Chr16_b 1
MCMT Chr17 0.18
tD Chr01 0.09
tD Chr05 0.00
tD Chr11 0.02
tD Chr13_a 0.04
tD Chr13_b 2.88
tD Chr14_a 5.25
tD Chr14_b 1
tD Chr15 1
tD Chr16_a 0.00
tD Chr16_b 1
tD Chr17 0.00
I want to convert my file into this format
env chr01 chr05 chr11 chr13_a chr13_b chr14_a chr14_b chr15 chr16_a chr16_b chr17
latitude 0.85 0.25 0.07 0.26 0 0 1 1 0.01 1 0.62
MCMT 1 0.3 0 0.34 0 0 1 1 0 1 0.18
TD 0.09 0 0.02 0.04 2.88 5.25 1 1 0 1 0
How can I do this?
text-processing columns
add a comment |
I have a file which looks like this:
latitude Chr01 0.85
latitude Chr05 0.25
latitude Chr11 0.07
latitude Chr13_a 0.26
latitude Chr13_b 0.00
latitude Chr14_a 0.00
latitude Chr14_b 1
latitude Chr15 1
latitude Chr16_a 0.01
latitude Chr16_b 1
latitude Chr17 0.62
MCMT Chr01 1
MCMT Chr05 0.30
MCMT Chr11 0.018
MCMT Chr13_a 0.34
MCMT Chr13_b 0.00
MCMT Chr14_a 0.00
MCMT Chr14_b 1
MCMT Chr15 1
MCMT Chr16_a 0.00
MCMT Chr16_b 1
MCMT Chr17 0.18
tD Chr01 0.09
tD Chr05 0.00
tD Chr11 0.02
tD Chr13_a 0.04
tD Chr13_b 2.88
tD Chr14_a 5.25
tD Chr14_b 1
tD Chr15 1
tD Chr16_a 0.00
tD Chr16_b 1
tD Chr17 0.00
I want to convert my file into this format
env chr01 chr05 chr11 chr13_a chr13_b chr14_a chr14_b chr15 chr16_a chr16_b chr17
latitude 0.85 0.25 0.07 0.26 0 0 1 1 0.01 1 0.62
MCMT 1 0.3 0 0.34 0 0 1 1 0 1 0.18
TD 0.09 0 0.02 0.04 2.88 5.25 1 1 0 1 0
How can I do this?
text-processing columns
1
Very similar to Transposing rows and columns
– Kusalananda
Feb 7 at 20:09
add a comment |
I have a file which looks like this:
latitude Chr01 0.85
latitude Chr05 0.25
latitude Chr11 0.07
latitude Chr13_a 0.26
latitude Chr13_b 0.00
latitude Chr14_a 0.00
latitude Chr14_b 1
latitude Chr15 1
latitude Chr16_a 0.01
latitude Chr16_b 1
latitude Chr17 0.62
MCMT Chr01 1
MCMT Chr05 0.30
MCMT Chr11 0.018
MCMT Chr13_a 0.34
MCMT Chr13_b 0.00
MCMT Chr14_a 0.00
MCMT Chr14_b 1
MCMT Chr15 1
MCMT Chr16_a 0.00
MCMT Chr16_b 1
MCMT Chr17 0.18
tD Chr01 0.09
tD Chr05 0.00
tD Chr11 0.02
tD Chr13_a 0.04
tD Chr13_b 2.88
tD Chr14_a 5.25
tD Chr14_b 1
tD Chr15 1
tD Chr16_a 0.00
tD Chr16_b 1
tD Chr17 0.00
I want to convert my file into this format
env chr01 chr05 chr11 chr13_a chr13_b chr14_a chr14_b chr15 chr16_a chr16_b chr17
latitude 0.85 0.25 0.07 0.26 0 0 1 1 0.01 1 0.62
MCMT 1 0.3 0 0.34 0 0 1 1 0 1 0.18
TD 0.09 0 0.02 0.04 2.88 5.25 1 1 0 1 0
How can I do this?
text-processing columns
I have a file which looks like this:
latitude Chr01 0.85
latitude Chr05 0.25
latitude Chr11 0.07
latitude Chr13_a 0.26
latitude Chr13_b 0.00
latitude Chr14_a 0.00
latitude Chr14_b 1
latitude Chr15 1
latitude Chr16_a 0.01
latitude Chr16_b 1
latitude Chr17 0.62
MCMT Chr01 1
MCMT Chr05 0.30
MCMT Chr11 0.018
MCMT Chr13_a 0.34
MCMT Chr13_b 0.00
MCMT Chr14_a 0.00
MCMT Chr14_b 1
MCMT Chr15 1
MCMT Chr16_a 0.00
MCMT Chr16_b 1
MCMT Chr17 0.18
tD Chr01 0.09
tD Chr05 0.00
tD Chr11 0.02
tD Chr13_a 0.04
tD Chr13_b 2.88
tD Chr14_a 5.25
tD Chr14_b 1
tD Chr15 1
tD Chr16_a 0.00
tD Chr16_b 1
tD Chr17 0.00
I want to convert my file into this format
env chr01 chr05 chr11 chr13_a chr13_b chr14_a chr14_b chr15 chr16_a chr16_b chr17
latitude 0.85 0.25 0.07 0.26 0 0 1 1 0.01 1 0.62
MCMT 1 0.3 0 0.34 0 0 1 1 0 1 0.18
TD 0.09 0 0.02 0.04 2.88 5.25 1 1 0 1 0
How can I do this?
text-processing columns
text-processing columns
edited Feb 7 at 21:25
Anna1364
asked Feb 7 at 19:48
Anna1364Anna1364
431212
431212
1
Very similar to Transposing rows and columns
– Kusalananda
Feb 7 at 20:09
add a comment |
1
Very similar to Transposing rows and columns
– Kusalananda
Feb 7 at 20:09
1
1
Very similar to Transposing rows and columns
– Kusalananda
Feb 7 at 20:09
Very similar to Transposing rows and columns
– Kusalananda
Feb 7 at 20:09
add a comment |
2 Answers
2
active
oldest
votes
There may be bioinformatics-specific tools for this - but otherwise you can use GNU datamash
$ datamash -s crosstab 1,2 unique 3 < file
Chr01 Chr05 Chr11 Chr13_a Chr13_b Chr14_a Chr14_b Chr15 Chr16_a Chr16_b Chr17
MCMT 1 0.30 0.018 0.34 0.00 0.00 1 1 0.00 1 0.18
latitude 0.85 0.25 0.07 0.26 0.00 0.00 1 1 0.01 1 0.62
tD 0.09 0.00 0.02 0.04 2.88 5.25 1 1 0.00 1 0.00
If the order of output lines is important, pipe the result through sort
BTW this isn't really transposition - it's cross-tabulation (sometimes known as a pivot table).
add a comment |
With miller (http://johnkerl.org/miller/doc)
mlr --inidx --ifs " " --opprint rename 1,env,2,key,3,value then reshape -s key,value input.txt
gives you
env Chr01 Chr05 Chr11 Chr13_a Chr13_b Chr14_a Chr14_b Chr15 Chr16_a Chr16_b Chr17
latitude 0.85 0.25 0.07 0.26 0.00 0.00 1 1 0.01 1 0.62
MCMT 1 0.30 0.018 0.34 0.00 0.00 1 1 0.00 1 0.18
tD 0.09 0.00 0.02 0.04 2.88 5.25 1 1 0.00 1 0.00
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499352%2fhow-to-generate-a-pivotal-table%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There may be bioinformatics-specific tools for this - but otherwise you can use GNU datamash
$ datamash -s crosstab 1,2 unique 3 < file
Chr01 Chr05 Chr11 Chr13_a Chr13_b Chr14_a Chr14_b Chr15 Chr16_a Chr16_b Chr17
MCMT 1 0.30 0.018 0.34 0.00 0.00 1 1 0.00 1 0.18
latitude 0.85 0.25 0.07 0.26 0.00 0.00 1 1 0.01 1 0.62
tD 0.09 0.00 0.02 0.04 2.88 5.25 1 1 0.00 1 0.00
If the order of output lines is important, pipe the result through sort
BTW this isn't really transposition - it's cross-tabulation (sometimes known as a pivot table).
add a comment |
There may be bioinformatics-specific tools for this - but otherwise you can use GNU datamash
$ datamash -s crosstab 1,2 unique 3 < file
Chr01 Chr05 Chr11 Chr13_a Chr13_b Chr14_a Chr14_b Chr15 Chr16_a Chr16_b Chr17
MCMT 1 0.30 0.018 0.34 0.00 0.00 1 1 0.00 1 0.18
latitude 0.85 0.25 0.07 0.26 0.00 0.00 1 1 0.01 1 0.62
tD 0.09 0.00 0.02 0.04 2.88 5.25 1 1 0.00 1 0.00
If the order of output lines is important, pipe the result through sort
BTW this isn't really transposition - it's cross-tabulation (sometimes known as a pivot table).
add a comment |
There may be bioinformatics-specific tools for this - but otherwise you can use GNU datamash
$ datamash -s crosstab 1,2 unique 3 < file
Chr01 Chr05 Chr11 Chr13_a Chr13_b Chr14_a Chr14_b Chr15 Chr16_a Chr16_b Chr17
MCMT 1 0.30 0.018 0.34 0.00 0.00 1 1 0.00 1 0.18
latitude 0.85 0.25 0.07 0.26 0.00 0.00 1 1 0.01 1 0.62
tD 0.09 0.00 0.02 0.04 2.88 5.25 1 1 0.00 1 0.00
If the order of output lines is important, pipe the result through sort
BTW this isn't really transposition - it's cross-tabulation (sometimes known as a pivot table).
There may be bioinformatics-specific tools for this - but otherwise you can use GNU datamash
$ datamash -s crosstab 1,2 unique 3 < file
Chr01 Chr05 Chr11 Chr13_a Chr13_b Chr14_a Chr14_b Chr15 Chr16_a Chr16_b Chr17
MCMT 1 0.30 0.018 0.34 0.00 0.00 1 1 0.00 1 0.18
latitude 0.85 0.25 0.07 0.26 0.00 0.00 1 1 0.01 1 0.62
tD 0.09 0.00 0.02 0.04 2.88 5.25 1 1 0.00 1 0.00
If the order of output lines is important, pipe the result through sort
BTW this isn't really transposition - it's cross-tabulation (sometimes known as a pivot table).
answered Feb 7 at 19:54
steeldriversteeldriver
36.4k35286
36.4k35286
add a comment |
add a comment |
With miller (http://johnkerl.org/miller/doc)
mlr --inidx --ifs " " --opprint rename 1,env,2,key,3,value then reshape -s key,value input.txt
gives you
env Chr01 Chr05 Chr11 Chr13_a Chr13_b Chr14_a Chr14_b Chr15 Chr16_a Chr16_b Chr17
latitude 0.85 0.25 0.07 0.26 0.00 0.00 1 1 0.01 1 0.62
MCMT 1 0.30 0.018 0.34 0.00 0.00 1 1 0.00 1 0.18
tD 0.09 0.00 0.02 0.04 2.88 5.25 1 1 0.00 1 0.00
add a comment |
With miller (http://johnkerl.org/miller/doc)
mlr --inidx --ifs " " --opprint rename 1,env,2,key,3,value then reshape -s key,value input.txt
gives you
env Chr01 Chr05 Chr11 Chr13_a Chr13_b Chr14_a Chr14_b Chr15 Chr16_a Chr16_b Chr17
latitude 0.85 0.25 0.07 0.26 0.00 0.00 1 1 0.01 1 0.62
MCMT 1 0.30 0.018 0.34 0.00 0.00 1 1 0.00 1 0.18
tD 0.09 0.00 0.02 0.04 2.88 5.25 1 1 0.00 1 0.00
add a comment |
With miller (http://johnkerl.org/miller/doc)
mlr --inidx --ifs " " --opprint rename 1,env,2,key,3,value then reshape -s key,value input.txt
gives you
env Chr01 Chr05 Chr11 Chr13_a Chr13_b Chr14_a Chr14_b Chr15 Chr16_a Chr16_b Chr17
latitude 0.85 0.25 0.07 0.26 0.00 0.00 1 1 0.01 1 0.62
MCMT 1 0.30 0.018 0.34 0.00 0.00 1 1 0.00 1 0.18
tD 0.09 0.00 0.02 0.04 2.88 5.25 1 1 0.00 1 0.00
With miller (http://johnkerl.org/miller/doc)
mlr --inidx --ifs " " --opprint rename 1,env,2,key,3,value then reshape -s key,value input.txt
gives you
env Chr01 Chr05 Chr11 Chr13_a Chr13_b Chr14_a Chr14_b Chr15 Chr16_a Chr16_b Chr17
latitude 0.85 0.25 0.07 0.26 0.00 0.00 1 1 0.01 1 0.62
MCMT 1 0.30 0.018 0.34 0.00 0.00 1 1 0.00 1 0.18
tD 0.09 0.00 0.02 0.04 2.88 5.25 1 1 0.00 1 0.00
edited Feb 8 at 11:05
answered Feb 8 at 10:58
aborrusoaborruso
22829
22829
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499352%2fhow-to-generate-a-pivotal-table%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Very similar to Transposing rows and columns
– Kusalananda
Feb 7 at 20:09