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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:54:00+00:00 2026-06-14T09:54:00+00:00

I have data arranged like this in R: indv time mass 1 10 7

  • 0

I have data arranged like this in R:

indv    time    mass
1         10    7
2          5    3
1          5    1
2          4    4
2         14    14
1         15    15

where indv is individual in a population. I want to add columns for initial mass (mass_i) and final mass (mass_f). I learned yesterday that I can add a column for initial mass using ddply in plyr:

sorted <- ddply(test, .(indv, time), sort)
sorted2 <- ddply(sorted, .(indv), transform, mass_i = mass[1])

which gives a table like:

   indv mass time mass_i
1    1    1    5      1
2    1    7   10      1
3    1   10   15      1
4    2    4    4      4
5    2    3    5      4
6    2    8   14      4
7    2    9   20      4

However, this same method will not work for finding the final mass (mass_f), as I have a different number of observations for each individual. Can anyone suggest a method for finding the final mass, when the number of observations may vary?

  • 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-14T09:54:02+00:00Added an answer on June 14, 2026 at 9:54 am

    You can simply use length(mass) as the index of the last element:

    sorted2 <- ddply(sorted, .(indv), transform,
                     mass_i = mass[1], mass_f = mass[length(mass)])
    

    As suggested by mb3041023 and discussed in the comments below, you can achieve similar results without sorting your data frame:

    ddply(test, .(indv), transform,
          mass_i = mass[which.min(time)], mass_f = mass[which.max(time)])
    

    Except for the order of rows, this is the same as sorted2.

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

Sidebar

Related Questions

Let's say I have a tab-delimited text file that contains data arranged in columns
I have a R data frame that looks like this: Country Property Value Canada
i have data-grid in my application and i want to customize my data-grid so
I have 'data.xlsx' file with cells of numbers and letters. when I run this
I have data like the following: var data = [{ id: 1, date: new
I have data stored in three columns of Excel Column A: Serial Number Column
I have data with no relation. Just need to count various columns from 3
I have about a hundred short-text data items (this number can vary substantially) that
I have a class that gets arranged into a hierarchy, such as this: class
I have data samples arranged in a 1000 x 56 array, and I would

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.