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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:34:15+00:00 2026-06-17T06:34:15+00:00

I am trying to use R to aggregate rows to columns. Here is a

  • 0

I am trying to use R to aggregate rows to columns. Here is a sample of my dataset.

age sex hash                                emotion     color
22  1   b17f9762462b37e7510f0e6d2534530d    Lonely      #006666
22  1   b17f9762462b37e7510f0e6d2534530d    Energetic   #66CC00
22  1   b17f9762462b37e7510f0e6d2534530d    Calm        #FFFFFF
22  1   b17f9762462b37e7510f0e6d2534530d    Angry       #FF0000
24  1   7bb50ca97a9b517239b39440a966d2f6    Calm        #006666
24  1   7bb50ca97a9b517239b39440a966d2f6    Excited     #0033cc
24  1   7bb50ca97a9b517239b39440a966d2f6    Empty/void  #999999
24  1   7bb50ca97a9b517239b39440a966d2f6    No emotion  #FF6600
26  1   209f1ba8ef86e855deccc0aae120825c    Comfortable #330066
21  1   b9e9309c0b1255a7efb2edf9ba66ae46    Energetic   #330099
21  1   b9e9309c0b1255a7efb2edf9ba66ae46    Happy       #330066
26  1   209f1ba8ef86e855deccc0aae120825c    No emotion  #FFCC00
26  1   209f1ba8ef86e855deccc0aae120825c    Calm        #006666
21  1   61debd3dea6d1aacce5c9fc7daec4fe5    Empty/void  #FFFFFF
21  1   b9e9309c0b1255a7efb2edf9ba66ae46    Calm        #006666
26  1   209f1ba8ef86e855deccc0aae120825c    No emotion  #339900
21  1   61debd3dea6d1aacce5c9fc7daec4fe5    Loved       #FF6600
26  1   209f1ba8ef86e855deccc0aae120825c    No emotion  #66CC00

What I want to do is get this:

age sex hash            #000000 #FF0000 ... #FFFFFF
22  1   8798tkojstwz9ei sad     happy   ... loved
...

One response is defined by the hash, associated data is age and sex.

I want to have each response as 1 instead of several columns. Each color should have it’s own column and the associated emotion as value of that column.

The whole dataset has 13 colors, 20+ emotions and 1000+ responses. The dataset looks exactly as the sample and is stored in a mySQL database.

I have tried with reshape, but it doesn’t play well with categorical data or I did not use the appropriate functions. Any ideas? It can include some mySQL preparation if needed. Java was here very slow and since I have 12k+ rows R sounds like the right thing for this.

Thank you.

  • 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-17T06:34:16+00:00Added an answer on June 17, 2026 at 6:34 am

    If I understand your objective correctly, reshape() is indeed the function you’re looking for. Assuming your dataset is called mydf, try this:

    reshape(mydf, direction = "wide", 
            idvar = c("hash", "age", "sex"), 
            timevar = "color")
    #    age sex                             hash emotion.#006666 emotion.#66CC00
    # 1   22   1 b17f9762462b37e7510f0e6d2534530d          Lonely       Energetic
    # 5   24   1 7bb50ca97a9b517239b39440a966d2f6            Calm            <NA>
    # 9   26   1 209f1ba8ef86e855deccc0aae120825c            Calm      No emotion
    # 10  21   1 b9e9309c0b1255a7efb2edf9ba66ae46            Calm            <NA>
    # 14  21   1 61debd3dea6d1aacce5c9fc7daec4fe5            <NA>            <NA>
    # emotion.#FFFFFF emotion.#FF0000 emotion.#0033cc emotion.#999999 emotion.#FF6600
    # 1             Calm           Angry            <NA>            <NA>            <NA>
    # 5             <NA>            <NA>         Excited      Empty/void      No emotion
    # 9             <NA>            <NA>            <NA>            <NA>            <NA>
    # 10            <NA>            <NA>            <NA>            <NA>            <NA>
    # 14      Empty/void            <NA>            <NA>            <NA>           Loved
    # emotion.#330066 emotion.#330099 emotion.#FFCC00 emotion.#339900
    # 1             <NA>            <NA>            <NA>            <NA>
    # 5             <NA>            <NA>            <NA>            <NA>
    # 9      Comfortable            <NA>      No emotion      No emotion
    # 10           Happy       Energetic            <NA>            <NA>
    # 14            <NA>            <NA>            <NA>            <NA>
    

    You can rename the columns later if you need to.

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

Sidebar

Related Questions

trying to use this route: from(activemq:profiles).aggregate(header(cheese)).batchSize(30).bean(ProfilesQueueService, saveContacts) Fails with: No signature of method: org.apache.camel.model.RouteType.aggregate()
I am need paint my image. I'm trying use JQuery in here this link:
I'm trying to use the aggregate function with cbind , but I must be
I am trying to understand how to use Aggregate roots and Aggregates, but I
I'm trying to create new aggregate function in PostgreSQL to use instead of the
I am trying to use Ladislav Mrnka's advice here to use: using System; using
Simple question I am trying to get the result of an aggregate to use
I'm trying to use pymongo and mongo's aggregation framework and here's what I got
I've been trying to use the aggregate function to group date fields by year:
i'm trying use facebook API to upload photo in my fan page. I downloaded

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.