[R] reshape -> reshape 2: function cast changed?

arun smartpink111 at yahoo.com
Wed Jul 25 19:03:53 CEST 2012


I tried with an example.  It looks like I am also getting the same error.  I am using R 2.15. 

dfm<-data.frame(Var1=rnorm(10,25),Var2=rnorm(10,15),Var3=rnorm(10,3),Var4=runif(10,0.4),Species=sample(LETTERS[1:4],10, replace=T))
  variable          A          B          C          D
#1     Var1 25.8125354 24.1405082 26.9989409 24.7531392
#2     Var2 15.5994468 13.8675085 16.5900085 16.4408974
#3     Var3  3.4704755  4.6132785  5.4582037  1.7146692
#4     Var4  0.8861144  0.9551669  0.9641575  0.4398574
Warning message:
In .fun(.value[0], ...) : no non-missing arguments to max; returning -Inf

Then, I did traceback()

> dcast(dfmmelt,variable~Species,value.var="value",max)
Error in .fun(.value[0], ...) : 
  (converted from warning) no non-missing arguments to max; returning -Inf
> traceback()
7: doWithOneRestart(return(expr), restart)
6: withOneRestart(expr, restarts[[1L]])
5: withRestarts({
       .Internal(.signalCondition(simpleWarning(msg, call), msg, 
       .Internal(.dfltWarn(msg, call))
   }, muffleWarning = function() NULL)
4: .signalSimpleWarning("no non-missing arguments to max; returning -Inf", 
       quote(.fun(.value[0], ...)))
3: vaggregate(.value = value, .group = overall, .fun = fun.aggregate, 
       ..., .default = fill, .n = n)
2: cast(data, formula, fun.aggregate, ..., subset = subset, fill = fill, 
       drop = drop, value.var = value.var)
1: dcast(dfmmelt, variable ~ Species, value.var = "value", max)

The output seems to be correct.


----- Original Message -----
From: Johannes Radinger <JRadinger at gmx.at>
To: r-help at r-project.org
Sent: Wednesday, July 25, 2012 6:14 AM
Subject: [R] reshape -> reshape 2: function cast changed?


I used to use reshape and moved to reshape2 (R 2.15.1). Now I tried some of my older scripts and was surprised that my cast function wasn't working like before.
What I did/want to do:
1) Melt a dataframe based on a vector specifying column names as measure.vars. Thats working so far:
dfm <- melt(df, measure.vars=n, variable_name = "species", na.rm = FALSE)

2) Recast the dataframe:
dfc <- cast(dfm, Var1 + Var2 + Var3 + Var4 ~ species,max) # with reshape
dfc <- dcast(dfm, Var1 + Var2 + Var3 + Var4 ~ species,max) # with reshape2

but then I get (this is new to reshape2!) a warning message:
In .fun(.value[0], ...) : no non-missing arguments to max; returning -Inf

The result seems to be similar (but I haven't checked it yet properly)? A message to ignore?

I use melt/cast/melt e.g. for multiple measurements (similar name in one column) to get only one row (one measurement) with e.g. the max value. Of course during the procedure I can also use cast/melt to drop columns that are not relevant for further processing.


R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list