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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:42:44+00:00 2026-06-18T06:42:44+00:00

I have trouble reshaping a data frame. Here is a sample data set: u<-data.frame(patient=1:9,time=1:3,var1=rnorm(9),var2=rnorm(9),var3=rnorm(9),var5=rnorm(9),var6=rnorm(9))

  • 0

I have trouble reshaping a data frame.

Here is a sample data set:

u<-data.frame(patient=1:9,time=1:3,var1=rnorm(9),var2=rnorm(9),var3=rnorm(9),var5=rnorm(9),var6=rnorm(9))

Instead of 6, I have 20 variables.

This only thing I want, is to make this wide data set into a long data set. Also, I have been searching on Stack Overflow/Google how to do this, but unsuccessful. Most reshape questions posted here seem way more difficult then what I am after.

What I am after is:

patient time    variable    value
1          1    var1        1.70484636
2          2    var1        0.19637999
3          3    var1        -1.20419038
4          1    var1        0.06944788
5          2    var1        -1.03074549
6          3    var1        0.9396862
7          1    var1        -0.57904879
8          2    var1        1.16163798
9          3    var1        1.11314472
1          1    var2        0.2138141
2          2    var2        2.9763986
3          3    var2        0.9686543
4          1    var2        0.1321531
5          2    var2        0.844687
6          3    var2        1.1336502
7          1    var2        0.5902222
8          2    var2        1.392971
9          3    var2        1.5335116
1          1    var3        0.93968 62
2          2    var3        2.9763986
3          3    var3        0.844687
....
  • 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-18T06:42:45+00:00Added an answer on June 18, 2026 at 6:42 am

    Did you come across the reshape2 package on your stackoverflow/Google search?

    require(reshape2)
    melt(u, id = c('patient', 'time'))
    #   patient time variable       value
    1        1    1     var1  0.25585248
    2        2    2     var1 -0.98750355
    3        3    3     var1 -0.12871163
    4        4    1     var1 -0.11789488
    5        5    2     var1 -1.16252583
    6        6    3     var1 -0.46498923
    7        7    1     var1 -2.11571402
    8        8    2     var1 -1.91485293
    9        9    3     var1 -0.19154752
    10       1    1     var2  2.38927206
    [skip]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble finding a way to link to class A to E. Here
I have trouble figuring out how do I load the rest of the data
I have trouble wrapping my head around a peculiar feature of the JSON data
I have trouble outputting some queried data which is stored in an array that
I have trouble connecting microstrategy to hive. I have followed every instruction here I
I have trouble finding the right way to add cells into columns: Here is
I have trouble in assigning an argument value / command line arguments. Here is
I have trouble to convert from decimal to hex. Here is my code: select
I have trouble of passing my get_profiles in the same template as r'^compose/$' here.
I have trouble here using fopen to open files which have paths longer than

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.