Re: [R] transforming data frame for use with persp

From: roger koenker <rkoenker_at_uiuc.edu>
Date: Tue 14 Feb 2006 - 08:19:23 EST

a strategy for this that I use is just

        persp(interp(x,y,z))

where interp is from the Akima package, and x,y,z are all of the same length.

url:    www.econ.uiuc.edu/~roger            Roger Koenker
email    rkoenker@uiuc.edu            Department of Economics
vox:     217-333-4558                University of Illinois
fax:       217-244-6678                Champaign, IL 61820


On Feb 13, 2006, at 3:07 PM, Denis Chabot wrote:

> 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
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
>
https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-
> guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Feb 14 08:22:29 2006

This archive was generated by hypermail 2.1.8 : Wed 15 Feb 2006 - 13:30:17 EST