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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:07:12+00:00 2026-05-26T04:07:12+00:00

I have a large data frame that Im working with, the first few lines

  • 0

I have a large data frame that Im working with, the first few lines are as follows:

      Assay   Genotype   Sample    Result
1     001        G         1         0
2     001        A         2         1
3     001        G         3         0 
4     001        NA        4         NA
5     002        T         1         0
6     002        G         2         1
7     002        T         3         0 
8     002        T         4         0
9     003        NA        1         N
10    003        G         2         1
11    003        G         3         1 
12    003        T         4         0

In total I’ll be working with 2000 samples and 168 Assays for each sample. For each sample, Id like extract the data in ‘Result’ for each sample to create either a list or data frame that looks something like this:

Sample  Data
   1    00N
   2    111
   3    001
   4    N00

The resulting data frame (or similar preferred data structure) would thus be 2000 rows and 2 columns. The ‘Data’ line would contain 168 characters each one for each ‘Assay’.

Can somebody help me with this problem?

  • 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-26T04:07:13+00:00Added an answer on May 26, 2026 at 4:07 am

    One approach with package plyr and base function paste:

    library(plyr)
    ddply(dat, "Sample", summarize, Data = paste(Result, collapse = ""))
    
      Sample Data
    1      1  00N
    2      2  111
    3      3  001
    4      4 NA00
    

    EDIT to address question

    Probably the easiest way I can think of to change your NA to N is to use gsub on the result of ddply. Note I’m liberally borrowing the very good point provided by @Brian re: ordering. Do that, it’s a good tip!

    out <- ddply(dat, "Sample", summarize, Data = paste(Result[order(Assay)], collapse = ""))
    

    Then use gsub

    out$Data <- gsub("NA", "N", out$Data)
    

    et voila:

      Sample Data
    1      1  00N
    2      2  111
    3      3  001
    4      4  N00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large data frame that Im working with, the first few lines
I'm working with a large data frame, and have run up against RAM limits.
I have a large data.frame that was generated by a process outside my control,
I have a large data frame (named z ) that looks like this: RPos
I have a large data.frame displaying some weird properties when plotted. I'd like to
I have a very large possible data set that I am trying to visualize
I have a data frame of integers that is a subset of all of
I have a large data.frame, and I'd like to be able to reduce it
I have a large data frame with the following fields (example data). #dput(data) gives...
I have a data.frame that looks like this > head(df) Memory Memory Memory Memory

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.