[R] transforming data frame for use with persp
Denis Chabot
chabotd at globetrotter.net
Mon Feb 13 22:07:32 CET 2006
Hi,
This is probably documented, but I cannot find the right words or
expression for a search. My attempts failed.
I have a data frame of 3 vectors (x, y and z) and would like to
transform this so that I could use persp. Presently I have y-level
copies of each x level, and a z value for each x-y pair. I need 2
columns giving the possible levels of x and y, and then a
transformation of z from a long vector into a matrix of x-level rows
and y-level columns. How do I accomplish this?
In this example, I made a set of x and y values to get predictions
from a GAM, then combined them with the predictions into a data
frame. This is the one I'd like to transform as described above:
My.data <- expand.grid(Depth=seq(40,220, 20), Temp=seq(-1, 6, 0.5))
predgam <- predict.gam(dxt.gam, My.data, type="response")
pred.data <- data.frame(My.data, predgam)
pred.data has 150 lines and 3 columns.
Thanks for your help,
Denis Chabot
More information about the R-help
mailing list