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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:28:43+00:00 2026-05-25T01:28:43+00:00

I need to change the format of my current data by creating a new

  • 0

I need to change the format of my current data by creating a new column as “tnum”(first column)to indicate trait/variable numbers and the last column “tval” to indicate each trait value.
My current data file (9,000 animals) is similar to this format:

anim <- c(201,202,203,204,205) 
bwt <- c(1.2,1.0,0.9,1.1,1.5)
leng <- c(14,21,18,16,19)
temp <- c(33,34,39,38,37) 
mydf <- data.frame(anim,bwt,leng,temp)

   anim bwt  leng  temp
1  201  1.2   14   33
2  202  1.0   21   34
3  203  0.9   18   39
4  204  1.1   16   38
5  205  1.5   19   37

Trait 1 = bwt, trait 2 = leng, and trait 3 = temp. This what I am looking for:

tnum    anim   tval
 1      201    1.2
 2      201    14
 3      201    33
 1      202    1.0
 2      202    21
 3      202    34
 1      203    0.9
 2      203    18
 3      203    39
 1      204    1.1
 2      204    16
 3      204    38
 1      205    1.5
 2      205    19
 3      205    37

Any help would be appreciated.

Baz

  • 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-25T01:28:44+00:00Added an answer on May 25, 2026 at 1:28 am
    library("reshape")
    m <- melt(mydf, id.vars="anim")
    m
       anim variable value
    1   201      bwt   1.2
    2   202      bwt   1.0
    3   203      bwt   0.9
    4   204      bwt   1.1
    5   205      bwt   1.5
    6   201     leng  14.0
    7   202     leng  21.0
    8   203     leng  18.0
    9   204     leng  16.0
    10  205     leng  19.0
    11  201     temp  33.0
    12  202     temp  34.0
    13  203     temp  39.0
    14  204     temp  38.0
    15  205     temp  37.0
    

    and please format your code better next time. its simple.

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

Sidebar

Related Questions

I have this script that works, but I need to change the format of
I need change background of all text that have two spaces from the start
i need change color of SystemTray.ProgressIndicator color, how i can do it? I tried
I have database, and in one the tables I need change the values of
I use Pjax with tutorial from http://railscasts.com/episodes/294-playing-with-pjax?view=comments I don't need change url and this
Need to change li position by clicking to move up or to move down.
I need to change the DataTemplate for items in a ListBox depending on whether
I need to change the functionality of an application based on the executable name.
I need to change the capitalization of a set of files in a subversion
I need to change a static property on an object in our web application.

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.