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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:44:30+00:00 2026-06-12T14:44:30+00:00

I have large dataset like the following: myd <- data.frame (var1 = c(A, A,

  • 0

I have large dataset like the following:

myd <- data.frame (var1 = c("A", "A", "B1-1", "B1-1", "C", "C", "D1", "D1"),
                   var2 = c(1,    2,    2,       2,     3,  1,   1,    4))
 var1 var2
1    A    1
2    A    2
3 B1-1    2
4 B1-1    2
5    C    3
6    C    1
7   D1    1
8   D1    4

Please note that each level in var1 is repeated twice and has two values in var2.

For each levels of var1, I want to create a new dataset where var2 values are now in row wise (shorted) and combined into one column with following type of output:

   var1    var2.h1 var2.h2      h1.h2  
1    A      1         2           12
2   B1-1    2         2           22
3    C      1         3           13
4   D1      1         4           14
  • 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-06-12T14:44:32+00:00Added an answer on June 12, 2026 at 2:44 pm
    library(plyr)
    ddply(myd, .(var1), function(x) {
         foo <- data.frame(rbind(x$var2), sprintf("%s%s", x$var2[1], x$var2[2]))
         names(foo) <- c("var2.h1", "var2.h2", "h1.h2")
         foo
        })
    
    var1 var2.h1 var2.h2 h1.h2
    1    A       1       2    12
    2 B1-1       2       2    22
    3    C       3       1    31
    4   D1       1       4    14
    
    • 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 with the following fields (example data). #dput(data) gives...
I've got a very large xml data set that is structured like the following:
I have a large real 1-d data set called r. I would like plot:
I have a large dataset that load in with a fill method on page
I have a large dataset that I am dealing with in Python. It is
Imagine you have a large dataset that may or may not be filtered by
i have a dataset which is like the following, however much larger: 5 6
I have a large data set that is updated once a day. I am
Assume I have a large dataset and I want to run a like function
I have a large dataset of philosophic arguments, each of which connect to other

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.