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 7410141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:11:14+00:00 2026-05-29T06:11:14+00:00

I have large set will a number of variables: set.seed (14) pool = sample

  • 0

I have large set will a number of variables:

set.seed (14)
pool = sample (c("AA","AB", "BB"), 100, replace = T) 
mydf <- data.frame (M1= pool[1:10], M2= pool[11:20],
M3= pool[21:30], M4= pool[31:40],  M5= pool[41:50], 
  M6= pool[51:60],  M7= pool[61:70], M8 = pool[71:80], 
  M9 = pool[81:90],  M10 = pool[91:100])

Need to install the package “hapassoc”, if previously installed.

install.packages(“hapassoc”)

>  library(hapassoc)
> example1.haplos <- pre.hapassoc(mydf, numSNPs = 3, allelic= F)

Haplotypes will be based on the following SNPs (genotypic format): 
 M8, M9, M10 
Remaining variables are: 
 M1, M2, M3, M4, M5, M6, M7

It is taking last 3 variables in group. But 1 want apply this function by breaking data into smaller pieces by group –

M1, M2, M3   group 1
M4, M5       group 2
M6, M7, M8   group 3
M9, M10      group 4 

Thus numSNPs would be represented by the following vector:

nsp <- c(3, 2, 3, 2)

I want to preserve the $haploMat for each group

example1.haplos$haploMat
 haplo1 haplo2
1    hBBA   hBAB
3    hAAB   hABB
4    hABA   hABA
6    hAAA   hBBA
7    hAAA   hAAA
8    hBBA   hBBB
9    hABB   hBBB
10   hABA   hBAB
12   hAAA   hBBB
13   hAAB   hBBA
14   hABA   hABA
15   hAAB   hBAB

The final output have eight columns group1.haplo1, goup1.haplo2, group2.haplo1, group2.haplo2, group3.haplo1, group4.haplo1, group4.haplo2.

How can I achieve this ?

  • 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-29T06:11:14+00:00Added an answer on May 29, 2026 at 6:11 am

    Is this what you’re after? (specify the column numbers of the groups as elements of the list assigned to grps). You’ll need the reshape2 package installed. You could do something similar with rbind.fill() from the plyr package.

    set.seed (14)
    pool = sample (c("AA","AB", "BB"), 100, replace = T) 
    mydf <- data.frame (M1= pool[1:10], M2= pool[11:20],
    M3= pool[21:30], M4= pool[31:40],  M5= pool[41:50], 
      M6= pool[51:60],  M7= pool[61:70], M8 = pool[71:80], 
      M9 = pool[81:90],  M10 = pool[91:100])
    
    library(hapassoc)
    
    grps <- list(1:3, 4:5, 6:8, 9:10)
    haplos <- lapply(grps, function(x) {
        out <- pre.hapassoc(mydf[, x], numSNPs=length(x), allelic=F, 
          verbose=F)$haploMat
        row.names(out) <- as.numeric(row.names(out))
        out
    })
    haplos <- lapply(haplos, t)
    library(reshape2)
    haplos <- melt(haplos,value.name='haplotype')
    haplos <- dcast(haplos, Var2 ~ L1 + Var1, value.var='haplotype')
    

    RESULT

    haplos
    
       Var2 1_haplo1 1_haplo2 2_haplo1 2_haplo2 3_haplo1 3_haplo2 4_haplo1 4_haplo2
    1     1     hABA     hABB      hBA      hBA     hAAA     hAAB      hAA      hAA
    2     2     <NA>     <NA>      hAB      hAB     hAAB     hABB      hAA      hAA
    3     3     hBAA     hAAB      hBA      hBB     hBBB     hBAA      hAA      hBA
    4     4     hBBB     hBAA      hBA      hAB     <NA>     <NA>      hAB      hBB
    5     5     <NA>     <NA>      hBB      hAA     hABB     hAAA      hAB      hBB
    6     6     hABB     hBBB      hBA      hBB     hABA     hAAB      hBB      hBB
    7     7     hBBB     hBBB      hAA      hAA     hBBB     hBAA      hAB      hBB
    8     8     hBBB     hABA      hBA      hAB     <NA>     <NA>      hAA      hAA
    9     9     <NA>     <NA>      hBB      hAA     hAAB     hAAB      hAA      hAB
    10   10     hBBB     hBAA      hAA      hBA     hABB     hBBB      hAB      hAB
    11   11     <NA>     <NA>      hBB      hBB     hBBA     hBBB     <NA>     <NA>
    12   12     hBBB     hABA      hAB      hBB     hABA     hABB     <NA>     <NA>
    13   13     <NA>     <NA>     <NA>     <NA>     hABB     hBAA     <NA>     <NA>
    14   14     hABB     hBBB     <NA>     <NA>     <NA>     <NA>     <NA>     <NA>
    15   15     <NA>     <NA>     <NA>     <NA>     hAAB     hBBA     <NA>     <NA>
    16   16     hBAA     hABA     <NA>     <NA>     hAAA     hBBB     <NA>     <NA>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a reasonably large set of strings (say 100) which has a number
I have a large set of data (a data cube of 250,000 X 1,000
I will need to supply a large data set consisting of numbers to a
I have a large set of files, some of which contain special characters in
I have a large set of XML files of a propriatary schema -the XML
I have a large set of numbers, probably in the multiple gigabytes range. First
I have a large set of words (about 10,000) and I need to find
I have a large set of values V, some of which are likely to
I have a large set of lines, which I render from a vertex buffer
If I have a large set of continuous ranges ( e.g. [0..5], [10..20], [7..13],[-1..37]

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.