Hello,
I am pasting two tables of 6x4 and 4x4 together to get a 10x8 output. I want to fill the blank values with a NaN (Not a Number). How can I do this?
Thanks,
Guss
Hello,
I am pasting two tables of 6x4 and 4x4 together to get a 10x8 output. I want to fill the blank values with a NaN (Not a Number). How can I do this?
Thanks,
Guss
IS this what you mean?
4x4
4 4 4 4
4 4 4 4
4 4 4 4
6x4
6 6 6 6
6 6 6 6
6 6 6 6
6 6 6 6
6 6 6 6
6 6 6 6
gives:
6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6
4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4
This is how I interpret you question. It doesn't make a lot of sense to me. Please give us sample input & desired output.
Hi Jim,
My file1 (6 rows x 4 columns) is:
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
My file2 (4 rows x 4 columns) is:
5 6 7 8
5 6 7 8
5 6 7 8
5 6 7 8
paste file1 -d '\t' file2 > file 3 as shown below
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4
1 2 3 4
However I wan the bottom two rows that do not have values for cols 5-8 to be filled with NaN (shown below using 'N' for abbreviation.)
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 N N N N
1 2 3 4 N N N N
Thanks for your input!
~Guss
paste t1 t2 | awk -v OFS="\t" '{ (NF>M) && M=NF; for(N=1; N<=M; N++) length($N) || $N="NaN" } 1'
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 NaN NaN NaN NaN
1 2 3 4 NaN NaN NaN NaN
$