Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6816649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:57:03+00:00 2026-05-26T20:57:03+00:00

I’d like to transform a table in such a way that for duplicated values

  • 0

I’d like to transform a table in such a way that for duplicated
values in column #2 it would have corresponding values from column #1.

I.e. something like that…

MZ00024296  AC148152.3_FG005

MZ00047079  AC148152.3_FG006

MZ00028122  AC148152.3_FG008

MZ00032922  AC148152.3_FG008

MZ00048218  AC148152.3_FG008

MZ00024680  AC148167.6_FG001

MZ00013456  AC149475.2_FG003

to

AC148152.3_FG005    MZ00024296

AC148152.3_FG006    MZ00047079

AC148152.3_FG008    MZ00028122|MZ00032922|MZ00048218

AC148167.6_FG001 MZ00024680

AC149475.2_FG003 MZ00013456

As I need it to computations in R I tried to use:

x=aggregate(mz_grmz,by=list(mz_grmz[,2]),FUN=paste(mz_grmz[,1],sep="|"))

but it don’t work (wrong function)
Error in match.fun(FUN) :
‘paste(mz_grmz[, 1], sep = “|”)’ is not a function, character or symbol

I also remind myself about unstack() function, but it isn’t what I need.

I tried to do it using awk, based on my base knowledge I reworked code given here:

site1

#! /bin/sh
for y do
awk -v FS="\t" '{
for (x=1;x<=NR;x++) {
    if (NR>2 && x=x+1) {
    print $2"\t"x
    }
    else {print NR}
}
}' $y > $y.2
done

unfortunately it doesn’t work, it’s only produce enormous file with field #2 and some numbers.

I suppose it is easy task, but it is above my skills right now.
Could somebody give me a hint? Maybe just function to use in aggregate in R.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:57:04+00:00Added an answer on May 26, 2026 at 8:57 pm

    You could do it in awk like this:

    awk '
        {
            if ($2 in a)
                a[$2] = a[$2] "|" $1
            else
                a[$2] = $1
        }
        END {
            for (i in a)
                print i, a[i]
        }' INFILE > OUTFILE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I would like to run a str_replace or preg_replace which looks for certain words
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.