added 'last' and 'first' functions to facilitate call as substfunc in eliminate_duplicated_variable_rows