Dear R Users, I'm trying to use the 'cast' function in the 'reshape' package to convert column-format data to gridded-format data. A sample of my dataset is as follows: head(finalframe) Latitude Longitude Temperature OrigLat p-value Blaney 1 -90 -38.75 NA -87.75 17.10167 NA 2 -90 135.75 NA -87.75 17.10167 NA 3 -90 80.25 NA -87.75 17.10167 NA 4 -90 95.75 NA -87.75 17.10167 NA 5 -90 66.75 NA -87.75 17.10167 NA 6 -90 75.75 NA -87.75 17.10167 NA I'm attempting to form a grid based on the OrigLat, Longitude and Blaney columns, to form the rows, columns and values of the new grid respectively. The command I've been using is: cast_test <- cast(finalframe, finalframe$OrigLat~variable, finalframe$Longitude~variable, finalframe$Blaney~variable) Error: Casting formula contains variables not found in molten data: finalframe$OrigLat, variable And I've tried removing the ~variable suffixes: cast_test <- cast(finalframe, finalframe$OrigLat, finalframe$Longitude, finalframe$Blaney) Error: Casting formula contains variables not found in molten data: -87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75 [etc etc] I'm not sure how to get round this error, nor what the 'molten data' is that the error is referring to. I'm assuming it means the data frame presented above, yet the variables are clearly present! Any help or advice on this would be most welcomed. Many thanks, Steve _________________________________________________________________ [[elided Hotmail spam]]
Is this what you want:> xLatitude Longitude Temperature OrigLat p.value Blaney 1 -90 -38.75 NA -87.75 17.10167 NA 2 -90 135.75 NA -87.75 17.10167 NA 3 -90 80.25 NA -87.75 17.10167 NA 4 -90 95.75 NA -87.75 17.10167 NA 5 -90 66.75 NA -87.75 17.10167 NA 6 -90 75.75 NA -87.75 17.10167 NA> y <- melt(x, measure='Blaney') > cast(y, OrigLat ~ Longitude, c)OrigLat -38.75 66.75 75.75 80.25 95.75 135.75 1 -87.75 NA NA NA NA NA NA On Mon, Aug 17, 2009 at 12:52 PM, Steve Murray<smurray444 at hotmail.com> wrote:> > Dear R Users, > > I'm trying to use the 'cast' function in the 'reshape' package to convert column-format data to gridded-format data. A sample of my dataset is as follows: > > head(finalframe) > ?Latitude Longitude Temperature OrigLat ?p-value Blaney > 1 ? ? ?-90 ? ?-38.75 ? ? ? ? ?NA ?-87.75 17.10167 ? ? NA > 2 ? ? ?-90 ? ?135.75 ? ? ? ? ?NA ?-87.75 17.10167 ? ? NA > 3 ? ? ?-90 ? ? 80.25 ? ? ? ? ?NA ?-87.75 17.10167 ? ? NA > 4 ? ? ?-90 ? ? 95.75 ? ? ? ? ?NA ?-87.75 17.10167 ? ? NA > 5 ? ? ?-90 ? ? 66.75 ? ? ? ? ?NA ?-87.75 17.10167 ? ? NA > 6 ? ? ?-90 ? ? 75.75 ? ? ? ? ?NA ?-87.75 17.10167 ? ? NA > > > I'm attempting to form a grid based on the OrigLat, Longitude and Blaney columns, to form the rows, columns and values of the new grid respectively. > > The command I've been using is: > > cast_test <- cast(finalframe, finalframe$OrigLat~variable, finalframe$Longitude~variable, finalframe$Blaney~variable) > Error: Casting formula contains variables not found in molten data: finalframe$OrigLat, variable > > And I've tried removing the ~variable suffixes: > > cast_test <- cast(finalframe, finalframe$OrigLat, finalframe$Longitude, finalframe$Blaney) > Error: Casting formula contains variables not found in molten data: -87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75 [etc etc] > > > I'm not sure how to get round this error, nor what the 'molten data' is that the error is referring to. I'm assuming it means the data frame presented above, yet the variables are clearly present! > > Any help or advice on this would be most welcomed. > > Many thanks, > > Steve > > > _________________________________________________________________ > > [[elided Hotmail spam]] > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
xavier.chardon at free.fr
2009-Aug-18 12:01 UTC
[R] Reshape package: Casting data to form a grid
Hi, You can't use cast directly on your dataframe. You need to use the melt function before, and use cast on its result. Very good examples are provided in the doc of the package: http://had.co.nz/reshape/ Also, you need to provide one formula (not several as in your code), something like: OrigLat ~ Longitude + variable (Or maybe something slightly different depending on what you want to do. ----- Mail Original ----- De: "Steve Murray" <smurray444 at hotmail.com> ?: r-help at r-project.org Envoy?: Lundi 17 Ao?t 2009 18h52:47 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne Objet: [R] Reshape package: Casting data to form a grid Dear R Users, I'm trying to use the 'cast' function in the 'reshape' package to convert column-format data to gridded-format data. A sample of my dataset is as follows: head(finalframe) Latitude Longitude Temperature OrigLat p-value Blaney 1 -90 -38.75 NA -87.75 17.10167 NA 2 -90 135.75 NA -87.75 17.10167 NA 3 -90 80.25 NA -87.75 17.10167 NA 4 -90 95.75 NA -87.75 17.10167 NA 5 -90 66.75 NA -87.75 17.10167 NA 6 -90 75.75 NA -87.75 17.10167 NA I'm attempting to form a grid based on the OrigLat, Longitude and Blaney columns, to form the rows, columns and values of the new grid respectively. The command I've been using is: cast_test <- cast(finalframe, finalframe$OrigLat~variable, finalframe$Longitude~variable, finalframe$Blaney~variable) Error: Casting formula contains variables not found in molten data: finalframe$OrigLat, variable And I've tried removing the ~variable suffixes: cast_test <- cast(finalframe, finalframe$OrigLat, finalframe$Longitude, finalframe$Blaney) Error: Casting formula contains variables not found in molten data: -87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75 [etc etc] I'm not sure how to get round this error, nor what the 'molten data' is that the error is referring to. I'm assuming it means the data frame presented above, yet the variables are clearly present! Any help or advice on this would be most welcomed. Many thanks, Steve _________________________________________________________________ [[elided Hotmail spam]] ______________________________________________ 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.
Dear Steve, You need something like this. cast(Latitude ~ Longitude, data = finalframe, value = "Blaney", fun mean) HTH, Thierry ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx at inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -----Oorspronkelijk bericht----- Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Namens Steve Murray Verzonden: maandag 17 augustus 2009 18:53 Aan: r-help at r-project.org Onderwerp: [R] Reshape package: Casting data to form a grid Dear R Users, I'm trying to use the 'cast' function in the 'reshape' package to convert column-format data to gridded-format data. A sample of my dataset is as follows: head(finalframe) Latitude Longitude Temperature OrigLat p-value Blaney 1 -90 -38.75 NA -87.75 17.10167 NA 2 -90 135.75 NA -87.75 17.10167 NA 3 -90 80.25 NA -87.75 17.10167 NA 4 -90 95.75 NA -87.75 17.10167 NA 5 -90 66.75 NA -87.75 17.10167 NA 6 -90 75.75 NA -87.75 17.10167 NA I'm attempting to form a grid based on the OrigLat, Longitude and Blaney columns, to form the rows, columns and values of the new grid respectively. The command I've been using is: cast_test <- cast(finalframe, finalframe$OrigLat~variable, finalframe$Longitude~variable, finalframe$Blaney~variable) Error: Casting formula contains variables not found in molten data: finalframe$OrigLat, variable And I've tried removing the ~variable suffixes: cast_test <- cast(finalframe, finalframe$OrigLat, finalframe$Longitude, finalframe$Blaney) Error: Casting formula contains variables not found in molten data: -87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75-87.75 -87.75-87.75 [etc etc] I'm not sure how to get round this error, nor what the 'molten data' is that the error is referring to. I'm assuming it means the data frame presented above, yet the variables are clearly present! Any help or advice on this would be most welcomed. Many thanks, Steve _________________________________________________________________ [[elided Hotmail spam]] ______________________________________________ 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. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.