Tom Vanwalleghem
2011-Aug-25 10:54 UTC
[R] apply function to spatial grid data frame to calculate CTI
Dear R helpers, I'm new to R and struggling with applying functions to a spatial grid data frame, called data for example.data has a variable named "slope" and "uparea" Basically, I need to calculate the tan(data$slope)Next, I need to divide data$uparea by data$slope and take the log() of that all In the basic examples I found how to make simple multiplications with a scalar likedata[["slope"]] = data[["slope"]]/2 # assigns new attribute I come from a background in GIS and fortran, so used to dealing with ordinary matrices, I'll admit I'm having trouble with understanding the format of this spatial grid data frame structureI've been trying different methods to index the data frame, or working with the function "lapply" but so far I can't seem to get my head wrapped around it. I appreciate any help.TomResearcher@University of CordobaSpain [[alternative HTML version deleted]]
Jean V Adams
2011-Aug-25 13:48 UTC
[R] apply function to spatial grid data frame to calculate CTI
It's not clear to me what problem you're having. tan(data$slope) should work. As should log(data$uparea/data$slope) I suggest that you provide a small subset of example data along with an example of any code you've tried, and the output that you'd like. Jean Tom Vanwalleghem wrote on 08/25/2011 05:54:01 AM:> > Dear R helpers, > I'm new to R and struggling with applying functions to a spatial > grid data frame, called data for example.data has a variable named > "slope" and "uparea" > Basically, I need to calculate the tan(data$slope)Next, I need to > divide data$uparea by data$slope and take the log() of that all > In the basic examples I found how to make simple multiplications > with a scalar likedata[["slope"]] = data[["slope"]]/2 # assigns newattribute> I come from a background in GIS and fortran, so used to dealing with > ordinary matrices, I'll admit I'm having trouble with understanding > the format of this spatial grid data frame structureI've been trying > different methods to index the data frame, or working with the > function "lapply" but so far I can't seem to get my head wrapped aroundit.> I appreciate any help.TomResearcher@University of CordobaSpain > [[alternative HTML version deleted]] >[[alternative HTML version deleted]]
Paul Hiemstra
2011-Aug-25 15:07 UTC
[R] apply function to spatial grid data frame to calculate CTI
On 08/25/2011 10:54 AM, Tom Vanwalleghem wrote:> Dear R helpers, > I'm new to R and struggling with applying functions to a spatial grid data frame, called data for example.data has a variable named "slope" and "uparea" > Basically, I need to calculate the tan(data$slope)Next, I need to divide data$uparea by data$slope and take the log() of that all > In the basic examples I found how to make simple multiplications with a scalar likedata[["slope"]] = data[["slope"]]/2 # assigns new attribute > I come from a background in GIS and fortran, so used to dealing with ordinary matrices, I'll admit I'm having trouble with understanding the format of this spatial grid data frame structureI've been trying different methods to index the data frame, or working with the function "lapply" but so far I can't seem to get my head wrapped around it. > I appreciate any help.TomResearcher at University of CordobaSpain > [[alternative HTML version deleted]] > > ______________________________________________ > 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.I would most surely take a look at the raster package, this might also be more intuitive for you. In addition, there is a special mailing list for spatial tasks, r-sig-geo. These kinds of questions are more suitable for that mailing list. cheers, Paul -- Paul Hiemstra, Ph.D. Global Climate Division Royal Netherlands Meteorological Institute (KNMI) Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 P.O. Box 201 | 3730 AE | De Bilt tel: +31 30 2206 494 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770