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

  • SEARCH
  • Home
  • 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 633675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:12:44+00:00 2026-05-13T20:12:44+00:00

Combining 2 columns into 1 column many times in a very large dataset in

  • 0

Combining 2 columns into 1 column many times in a very large dataset in R

The clumsy solutions I am working on are not going to be very fast if I can get them to work and the true dataset is ~1500 X 45000 so they need to be fast. I definitely at a loss for 1) at this point although have some code for 2) and 3).

Here is a toy example of the data structure:

pop = data.frame(status = rbinom(n, 1, .42), sex = rbinom(n, 1, .5),
age = round(rnorm(n, mean=40, 10)), disType = rbinom(n, 1, .2),
rs123=c(1,3,1,3,3,1,1,1,3,1), rs123.1=rep(1, n), rs157=c(2,4,2,2,2,4,4,4,2,2),
rs157.1=c(4,4,4,2,4,4,4,4,2,2),  rs132=c(4,4,4,4,4,4,4,4,2,2),
rs132.1=c(4,4,4,4,4,4,4,4,4,4))

Thus, there are a few columns of basic demographic info and then the rest of the columns are biallelic SNP info. Ex: rs123 is allele 1 of rs123 and rs123.1 is the second allele of rs123.

1) I need to merge all the biallelic SNP data that is currently in 2 columns into 1 column, so, for example: rs123 and rs123.1 into one column (but within the dataset):

11
31
11
31
31
11
11
11
31
11

2) I need to identify the least frequent SNP value (in the above example it is 31).

3) I need to replace the least frequent SNP value with 1 and the other(s) with 0.

  • 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-13T20:12:44+00:00Added an answer on May 13, 2026 at 8:12 pm

    Do you mean ‘merge’ or ‘rearrange’ or simply concatenate? If it is the latter then

    R> pop2 <- data.frame(pop[,1:4], rs123=paste(pop[,5],pop[,6],sep=""), 
    +                                rs157=paste(pop[,7],pop[,8],sep=""), 
    +                                rs132=paste(pop[,9],pop[,10], sep=""))
    R> pop2
       status sex age disType rs123 rs157 rs132
    1       0   0  42       0    11    24    44
    2       1   1  37       0    31    44    44
    3       1   0  38       0    11    24    44
    4       0   1  45       0    31    22    44
    5       1   1  25       0    31    24    44
    6       0   1  31       0    11    44    44
    7       1   0  43       0    11    44    44
    8       0   0  41       0    11    44    44
    9       1   1  57       0    31    22    24
    10      1   1  40       0    11    22    24
    

    and now you can do counts and whatnot on pop2:

    R> sapply(pop2[,5:7], table)
    $rs123
    
    11 31 
     6  4 
    
    $rs157
    
    22 24 44 
     3  3  4 
    
    $rs132
    
    24 44 
     2  8 
    
    R> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any tips on combining multiple .js files into 1 (for a build process). Will
Is there any gain to combining all of the classes for a project into
I am combining 2 tables into 1, by using the following statements Select Calls.*,Patient.*
i am working on a legacy enterprise database that uses multiple columns to retrieve
I've done all of this in active record, but it's not going to work
I have a large table with 27 columns and between 5 to 100 rows.
Does combining an Enterprise Messaging solution with Web Services result in a real performance
I've just started combining my knowledge of C++ classes and dynamic arrays. I was
I'm having trouble combining a url query parameter rewrite (fancy-url) with a .htaccess ssl
The ASP.NET team released the script combining feature in 3.5 SP1 as detailed here

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.