in reply to Is it possible to merge data frames with different amounts of rows?

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