Hi, 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. /Johannes
reshape -> reshape 2: function cast changed?
3 messages · Johannes Radinger, Jeff Newmiller, arun
Not really answering your posed question, but
a) reshape2 uses dcast and acast
b) The "cast" step of "melt-cast-melt" can invoke plyr, and it seems like MCM is just a very inefficient way for you to get at the plyr functionality. Perhaps you should take a more direct route to your goal?
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Johannes Radinger <JRadinger at gmx.at> wrote:
Hi, 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. /Johannes
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
HI, 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)) dfmmelt<-melt(dfm,id="Species",na.rm=FALSE) dcast(dfmmelt,variable~Species,max) ? 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() ?options(warn=2)
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,
?????????? call))
?????? .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.
A.K.
----- Original Message -----
From: Johannes Radinger <JRadinger at gmx.at>
To: r-help at r-project.org
Cc:
Sent: Wednesday, July 25, 2012 6:14 AM
Subject: [R] reshape -> reshape 2: function cast changed?
Hi,
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.
/Johannes
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.