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

The Archive Base Latest Questions

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

cast , from the reshape2 package, can handle a bunch of functions if passed

  • 0

cast, from the reshape2 package, can handle a bunch of functions if passed directly in the call. For example:

library(reshape2)

d <- data.frame(variable="variable",value=rnorm(100))
cast(d, variable ~ ., c(mean,sd,max,min))

But, this doesn’t work if you try to build the list of functions before hand. For example:

summary.fun <- c(mean,sd,max,min)
cast(d, variable ~., summary.fun) 

I looked at the code for cast that deals with this particular behaviour and, to be honest, I have no idea what it’s doing:

if (length(fun.aggregate) > 1) 
        fun.aggregate <- do.call(funstofun, as.list(match.call()[[4]])[-1])

Is there a way to pass a premade list of functions as a variable to cast()?

  • 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-15T06:32:09+00:00Added an answer on June 15, 2026 at 6:32 am

    Your function has to use an input argument. The function cast automatically passes the values as the first argument to the function. Furthermore, you have to tell R that summary.fun is a function using <- function().

    summary.fun <- function(x) list(mean(x), sd(x), max(x), min(x))
    

    Try this function with cast.

    library(reshape)
    
    d <- data.frame(variable="variable",value=rnorm(100))
    
    cast(d, variable ~ ., summary.fun)
    

    As @handley pointed out, this does not work with the cast function from the reshape2 package. You should have a look at dcast and acast.

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

Sidebar

Related Questions

I use cast() from the reshape package quite frequently. Almost every time, this warning
I have a class Something that implements ISomething . How can I convert/cast from
How can i cast from ObservableCollection<TabItem> into ObservableCollection<object> this doesnt work for me (ObservableCollection<object>)myTabItemObservableCollection
Possible Duplicate: What happens when you cast from short to byte in C#? Can
I saw in a blog that you can cast from string to int and
The following code example demonstrates that the implicit cast from short to char fires
In what scenarios can be reinterpret_cast used to cast from a base pointer that's
I've been searching but I can't find how to cast from the type Expression<Func<T,
How can I cast from a String to a long in a Scala play
Subsonic 2.2 is throwing the error subsonic Invalid cast from System.Int32 to System.Byte[] When

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.