gridding values in a data frame
It's hard to check without a reproducible example, but the following code should give you a 3d array of lat x long x time: library(reshape) df$lat <- round_any(df$LATITUDE, 5) df$long <- round_any(df$LONGITUDE, 5) df$value <- df$TIME cast(df, lat ~ long ~ time, mean)
On Thu, Apr 30, 2009 at 10:55 AM, dxc13 <dxc13 at health.state.ny.us> wrote:
Hi all, I have a data frame that looks like such: LATITUDE ? LONGITUDE ? TEMPERATURE ? TIME 36.73 ? ? ? ? -176.43 ? ? ? ?58.32 ? ? ? ? ? ? ? 1 50.95 ? ? ? ? ? ?90.00 ? ? ? ?74.39 ? ? ? ? ? ? ? 1 -30.42 ? ? ? ? ? ?5.45 ? ? ? ?23.26 ? ? ? ? ? ? ? 1 15.81 ? ? ? ? -109.31 ? ? ? ?52.44 ? ? ? ? ? ? ? 1 -80.75 ? ? ? ?-144.95 ? ? ? ?66.19 ? ? ? ? ? ? ?2 90.00 ? ? ? ? ?100.55 ? ? ? ?37.50 ? ? ? ? ? ? ? 2 65.41 ? ? ? ? -4.49 ? ? ? ? ? 29.83 ? ? ? ? ? ? ? 2 and this goes on for a A LOT more records, until time=1200 I want to create a 5 degree by 5 degree grid of this data, with the value of temperature in the appropriate grid cell. ?I want one grid for each time value. ?For each time value, this works out to be a 36x72 grid with 2592 cells because the longitude spans -180 to 180 and latitude spans 90 to -90 and they would be in increments of 5 degrees. ?If there are no temperatures available to be put into a grid cell, than that cell should get a missing value, NA, put into it. Also, could the gridded result for each time be written to a text file before processing the next time value? Hope this is clear. Thanks in advance. dxc13 -- View this message in context: http://www.nabble.com/gridding-values-in-a-data-frame-tp23319190p23319190.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.