Dataframe transformation (preparation to sql export) dataframe r sql transformation How to make such transformation as in the below image ?