G'day Mauri1313,

Welcome to the Monastery.

In addition to the issues pointed out by haj, I see:

[I appreciate this is your first post here. For future reference, please read "How do I post a question effectively?": a clearer post results in less guesswork from us and a quicker and better answer for you.]

In order to produce the output you show from the two inputs you presented, I might write something like this:

#!/usr/bin/env perl use strict; use warnings; use autodie; my $main_df_file = 'pm_11131885_main_df'; my $comp_df_file = 'pm_11131885_comp_df'; my %val_for; { open my $comp_df_fh, '<', $comp_df_file; while (<$comp_df_fh>) { next if $. == 1; chomp; my (undef, $id, undef, $val) = split /\s+/; my $key = (split /\./, $id)[0]; $val_for{$key} = $val unless exists $val_for{$key}; } } { my @out_headers = qw{ID1 ID2 dN dS Omega Value Label_ID1 Label_ID2 + Group}; my $out_fmt = "%-8s\t%-8s\t%-6s\t%-6s\t%-6s\t%-7s\t%-13s\t%-13s\t% +-5s\n"; my @pre_val_indices = 0 .. 4; my @post_val_indices = 5 .. 7; my $no_match_val = ' -'; my %seen; printf $out_fmt, @out_headers; open my $main_df_fh, '<', $main_df_file; while (<$main_df_fh>) { next if $. == 1; chomp; next unless length; my @elements = split /\s+/; my $key = $elements[0]; next if $seen{$key}++; my $val = exists($val_for{$key}) ? $val_for{$key} : $no_match_ +val; printf $out_fmt, @elements[@pre_val_indices], $val, @elements[@post_val_ind +ices]; } }

Output:

ID1 ID2 dN dS Omega Value Label_ +ID1 Label_ID2 Group AVP78042 AVP78031 0.0059 0.1188 0.0500 0.29731 SARSr- +bat-CoV SARSr-bat-CoV Intra ATO98108 AVP78031 0.1373 1.4673 0.0936 - SARSr- +bat-CoV SARSr-bat-CoV Intra

That might be exactly what you're looking for; if not, it may provide some ideas about how to tackle the problem.

— Ken


In reply to Re: Is it possible to merge data frames with different amounts of rows? by kcott
in thread Is it possible to merge data frames with different amounts of rows? by Mauri1313

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.