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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:30:25+00:00 2026-05-26T13:30:25+00:00

I would like to reshape a data frame of dimensions 103740 x 4 into

  • 0

I would like to reshape a data frame of dimensions 103740 x 4 into wide format, i.e., to go from the first block of text below to the second. The following function works well enough when applied to part of the data frame but it exhausts my machine’s available memory when applied to the full data frame:

reshape(analysis1[1:8], idvar=c("name", "sire_name"), 
        timevar = "course", direction = "wide")[, -c(1,2)]  

What are some better ways to unstack this data frame?

           name sire_name        course appearance
1      A Beetoo   Bahhare       Kempton          0
2      A Beetoo   Bahhare     Lingfield          9
3      A Beetoo   Bahhare     Southwell          0
4      A Beetoo   Bahhare Wolverhampton          0
5 A Bid In Time  Danetime       Kempton          0
6 A Bid In Time  Danetime     Lingfield          3
7 A Bid In Time  Danetime     Southwell          2
8 A Bid In Time  Danetime Wolverhampton          2
...

  Kempton Lingfield Southwell Wolverhampton
1       0         9         0             0
5       0         3         2             2
...

I’ve tried moving the data frame into a data table, but just doing this alone doesn’t seem to help.

  • 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-26T13:30:26+00:00Added an answer on May 26, 2026 at 1:30 pm

    When you want it very simple like this reshaping in base R would be most efficient. I’d just make a matrix out of appearance, cast it to a data.frame type, and name the columns.

    newDF <- data.frame( matrix(oldDF$appearance, ncol = 4, byrow = TRUE) )
    names(newDF) <- oldDF$course[1:4]
    

    Now, if you don’t have the frame sorted just as you’ve presented it and maybe even have more values in the course column the following is more robust…

    oldDF <- oldDF[ order(oldDF$course), ]
    s <- sort(unique(oldDF$course))
    newDF <- data.frame( matrix(oldDF$appearance, ncol = length(s)) )
    names(newDF) <- s
    

    (you can add other columns to the order function to break ties if you wish)

    One of the great advantages of the many commands that can be used to reshape your data and is that they are robust to the order of the data, missing cells, etc. However, this also makes them generally quite slow when you’ve got a straightforward reshape on a very large data.frame object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to reshape a data frame from long to wide (dummy data given
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
I have some trouble to convert my data.frame from a wide table to a
I am struggling with transformation of a Panel Dataset from wide to long format.
I have some data represented in a 1300x1341 matrix. I would like to split
I would like to store and load numpy arrays from binary files. For that
I have a file that I would like to reshape it to use R:
I have a data.frame in panel format (country-year) and I need to calculate the
Suppose that we have a data frame that looks like set.seed(7302012) county <- rep(letters[1:4],
I have a data frame that follows the below long Pattern: Name MedName Name1

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.