Help for a Perl newcomer! Transposing data from columns to rows
I have to create a Perl script which will transpose the data output from my experiment, from columns to rows, in order for me to analyse the data.
I am a complete Perl novice so any help would be greatly appreciated.
The data as it stands looks like this:
(But the real data file is much bigger, with each subject having 8 rows, and across the top, where it reads Fp1 etc. there are 64 items like this)
I need the data to look like this to analyse:
I need each subject to only have one row, and the condition column removed. The conditions need to then be specified along side each item at the top (so Fp1 repeated 4 times, with each condition next to it, Fp2 repeated 4 times with each condition next to it etc...)
In the real data set, as mentioned, there are 64 items along the top (so 64 different e.g Fp1) and there are 8 conditions for each subject (not four as my above example shows). there are 22 subjects in total in the data set too.
If any other information is needed feel free to ask.
Any sample scripts that I can use would be greatly appreciated, thanks!
---------- Post updated at 06:42 PM ---------- Previous update was at 06:41 PM ----------
Sorry the examples of my data have not aligned properly when i posted the thread but hopefully you can still understand what i mean!
...Is there any way of getting the output to save in a file, so I can open it and run my analysis?
...
One way to do that would be to use the shell's redirection operator to redirect the output to a file -
The command above makes the shell redirect the input data from "data_file" to the Perl program "script.pl" and redirect the output to the file "output_file".
Once the execution is over, you could open "output_file" for further processing.
tyler_durden
This User Gave Thanks to durden_tyler For This Post:
Thanks, I can run the script now and save the output however the script does not appear to be doing what I wanted and what you managed to get it to do!
Can you suggest what I may be doing wrong or any way to alter the script to get it to allign the collumns by subject number correctly?!
Thanks, I can run the script now and save the output however the script does not appear to be doing what I wanted and what you managed to get it to do!
As in this is the output i get:
nothing alligned, nothing arranged by subject, the conditions are not specified by the items at the top, it just comes out a random arrangement like above..
It needs to be arranged by condition and item on the top row, with each subject only having one row.
Any help with this is greatly appreciated!
Last edited by Franklin52; 12-03-2011 at 11:37 AM..
Reason: Please use code tags for data and code samples, thank you
Hi,
I am trying to transpose rows to columns for thousands of records. The problem is there are records that have the same lines that need to be separated. the input file as below:-
ID 1A02_HUMAN
AC P01892; O19619; P06338; P10313; P30444; P30445; P30446; P30514;
AC Q29680; Q29837;... (2 Replies)
Here is the contents of an input file.
A,1,2,3,4
10,aaa,bbb,ccc,ddd
11,eee,fff,ggg,hhh
12,iii,jjj,lll,mmm
13,nnn,ooo,ppp
I wanted the output to be
A
10 1 aaa
10 2 bbb
10 3 ccc
10 4 ddd
11 1 eee
11 2 fff
11 3 ggg
11 4 hhh .....
and so on How to do it in ksh... (9 Replies)
Hi, I need to transpose columns of my files into rows and save it as individual files. sample contents of the file below.
0.9120 0.7782 0.6959 0.6904 0.6322 0.8068 0.9082
0.9290 0.7272 0.9870 0.7648 0.8053 0.8300 0.9520
0.8614 0.6734 0.7910 0.6413 0.7126 0.7364 0.8491
0.8868 0.7586 0.8949... (8 Replies)
Hello. very new to shell scripting and would like to know if anyone could help me.
I have data thats being pulled into a txt file and currently have to manually transpose the data which is taking a long time to do.
here is what the data looks like.
Server1 -- Date -- Other -- value... (7 Replies)
I have 1000s of these rows that I would like to transpose to columns. However I would like the transpose every 3 consecutive rows to columns like below, sorted by column 3 and provide a total for each occurrences. Finally I would like a grand total of column 3.
21|FE|41|0B
50\65\78
15... (2 Replies)
I'm working on a different stage of a project that someone helped me address elsewhere in these threads.
The .docs I'm cycling through look roughly like this:
1 of 26 DOCUMENTS
Copyright 2010 The Age Company Limited
All Rights Reserved
The Age (Melbourne, Australia)
November 27, 2010... (9 Replies)
I have a file like the one given below
P1|V1|V2
P1|V1|V3
P1V1|V2
P2|V1|V4
P2|V2|V6
P2|V1|V4
I want it convert to
P1|V1|V2|V2|V3
P2|V1|V4|V2|V6
2nd and 3rd column should be considered as together and so the tird row is duplicate
Any ideas? (3 Replies)
Hi,
I am a beginner in bash&perl.
I have data in form of:-
A 1
B 2
C 3
D 4
E 5
I would like your help to find a simple way to change it to :-
A B C D E
1 2 3 4 5
Any help would be highly appreciated. (8 Replies)