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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:25:08+00:00 2026-06-12T08:25:08+00:00

Aloha, I am trying to cast() a dataset in which every unique combination of

  • 0

Aloha,

I am trying to cast() a dataset in which every unique combination of W-X-Y returns the max number of Z AND the associated week. For example:

W       X       Y       week    Z  
w1      x1      y1      1       0  
w1      x1      y1      2      0.1  
w1      x1      y1      3      0.2  
w2      x2      y1      1      0.5   
w2      x2      y1      2      0.7  
w2      x2      y1      3      0.3  
w3      x1      y1      1      0.1  
w3      x1      y1      2      0.2  
w3      x1      y1      3      0.5  
w4      x2      y2      1      0.7  
w4      x2      y2      2      0.3  
w4      x2      y2      3      0.1  
w5      x1      y2      1      0.3  
w5      x1      y2      2      0.1  
w5      x1      y2      3      0.2  

Can I do this w/cast()? I am able to return just the max number of Z per unique W-X-Y combination, but not the week with the following:

cast(foo, W + X + Y ~ ., max, value="Z")

For the above dataset, I would like the output to look as such:

W       X       Y       week    Z
w1      x1      y1      3      0.2
w2      x2      y1      2      0.7 
w3      x1      y1      3      0.5 
w4      x2      y2      1      0.7 
w5      x1      y2      1      0.3  

Mahalo for your suggestions!

  • 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-12T08:25:09+00:00Added an answer on June 12, 2026 at 8:25 am

    cast is not the right tool for this. Consider instead the functions in the plyr package:

    library("plyr")
    ddply(foo, .(W, X, Y), summarise, week=week[which.max(Z)], Z=max(Z))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Generic repository and are trying to cast the .Returns to a
Trying to replace any non alpha-numeric characters with a hyphen. Can't see why it
I am trying to cast a datastream into a struct since the datastream consists
In pretty much any normal programming language, one can cast an integer/short/byte into a
i'm trying to modify a image, which is casted from a String: [Embed(source='map.swf', symbol='wZero')]
Aloha! Trying to run a basic validation on a postal code input, and additionally
i'm trying to set up a custom action in Aloha, adding a button that
I am trying to find record with names which have non-alpha numeric characters. I
Aloha, I'm trying to populate a treeview on a windows form app with Hierarchical
Accoriding to the Aloha Editor docs you can listen for the aloha-smart-content-changed event for

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.