Heaven
March 13, 2012, 10:40am
1
Hello my problem is that:
I have several files with 4 columns and I want to calculate mode of 4th column for each file and write 2nd 3rd and mode value as an output file.
Here is an example of my files:
2005-01-21 05:30:00 0.518736 -163
2005-01-20 05:30:00 0.518736 -160
2005-01-22 05:30:00 0.518736 -159
2005-01-23 05:30:00 0.518736 -157
2005-12-25 05:30:00 0.518736 -157
2005-12-26 05:30:00 0.518736 -157
2005-12-22 05:30:00 0.518736 -156
2005-12-30 05:30:00 0.518736 -156
2005-12-05 05:30:00 0.518736 -155
2005-12-17 05:30:00 0.518736 -155
2005-12-21 05:30:00 0.518736 -155
2005-12-23 05:30:00 0.518736 -155
2005-12-24 05:30:00 0.518736 -155
2005-12-31 05:30:00 0.518736 -155
2005-01-03 05:30:00 0.518736 -154
the output file must contain all the mode values with corresponding $2 and $3
Could you please help me with this..
Thank you all.
Please, display the desired output.
From what I understood:
$ cat input
2005-01-21 05:30:00 0.518736 -163
2005-01-20 05:30:00 0.518736 -160
2005-01-22 05:30:00 0.518736 -159
2005-01-23 05:30:00 0.518736 -157
2005-12-25 05:30:00 0.518736 -157
2005-12-26 05:30:00 0.518736 -157
2005-12-22 05:30:00 0.518736 -156
2005-12-30 05:30:00 0.518736 -156
2005-12-05 05:30:00 0.518736 -155
2005-12-17 05:30:00 0.518736 -155
2005-12-21 05:30:00 0.518736 -155
2005-12-23 05:30:00 0.518736 -155
2005-12-24 05:30:00 0.518736 -155
2005-12-31 05:30:00 0.518736 -155
2005-01-03 05:30:00 0.518736 -154
$
$ perl -ane '$x{$F[3]}++;
END {
$val = 0; $key = 0;
while (($k, $v) = each %x) {
if ($v > $val) { $key = $k; $val = $v }
}
open I, "< input";
for (<I>) {
chomp; @y = split /\s+/;
print "$y[1]\t$y[2]\t$key\n";
}
close I;
}' input
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
05:30:00 0.518736 -155
$
Heaven
March 14, 2012, 3:27am
4
Hello,
i want my output like this:
05:30:00 0.518736 -155
i mean i want one mode value for my all files and then each values should be together in a file. Because all files have different frequencies and times. First i want to calculate mode values from my all files then the output file must contain all the mode values with corresponding frequencies and time:
for example:
05:30:00 0.100000 -162
05:30:00 0.500000 -154
05:30:00 0.518736 -155