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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:38:03+00:00 2026-06-02T17:38:03+00:00

Assuming I have a melted data.frame that looks like this: variable value 1 A

  • 0

Assuming I have a melted data.frame that looks like this:

  variable       value
1         A -0.19933093
2         A -1.19043346
3         A -1.32248172
4         A -1.98644507
5         A -0.07930953
6         B -0.10074686
7         B  0.72451483
8         B -0.40914044
9         B  0.02913376
10        B  0.16062491

How do I get it to:

  A       B
-0.19933093 -0.10074686
-1.19043346  0.72451483
-1.32248172 -0.40914044
-1.98644507  0.02913376
-0.07930953  0.16062491

Seems trivial but I am blanking on an answer. dcast and acast do not seem to do it. My goal is to do this on larger datasets and turn the end product into a matrix with the column names to be the variable names. I tried playing with daply and laply (before melting) without much luck.

  • 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-02T17:38:06+00:00Added an answer on June 2, 2026 at 5:38 pm

    Try unstack:

    dat <- read.table(text = "variable       value
    1         A -0.19933093
    2         A -1.19043346
    3         A -1.32248172
    4         A -1.98644507
    5         A -0.07930953
    6         B -0.10074686
    7         B  0.72451483
    8         B -0.40914044
    9         B  0.02913376
    10        B  0.16062491",sep = "",header = TRUE)
    
    > unstack(dat,value~variable)
    
                A           B
    1 -0.19933093 -0.10074686
    2 -1.19043346  0.72451483
    3 -1.32248172 -0.40914044
    4 -1.98644507  0.02913376
    5 -0.07930953  0.16062491
    

    But I should add that I would love to know how to do this using dcast, as I’ve also tried repeatedly and haven’t been able to.

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

Sidebar

Related Questions

Assuming I have an Entity Framework 4.2 class like this: class Company { public
Assuming you have a hypothetical enum in java like this (purely for demonstration purposes,
Assuming I have a class like this: class Base { } class A :
Assuming I have a class like this: class Database { public static $hostname =
Assuming I have a table foo where I have something like this: id ,
Assuming I have an attached property defined like that : public static string GetMyProperty(DependencyObject
Assuming we have a salt that's in the database and that has been generated
Assuming I have a class with a method that takes a System.Linq.Expressions.Expression as a
Assuming I have a schema that describes a root element class Root that contains
Assuming I have a table with one field called ID that stores 100 different

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.