[R-sig-Geo] suggestion to write a more elegant code
Alexander Brenning
brenning at uwaterloo.ca
Fri Oct 17 02:01:18 CEST 2008
Hi,
first, your formulas should read ~a^1.4 etc.; 'a' represents the first
(and in your case only) grid in in.grids.
Instead of using a formula, you can use a character string:
formula = "a^1.5" etc.,
so you just have to 'paste' things together; this should work:
for (pow in seq(1.5, 4.0, by = 0.1))
rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),
out.grid = "DCM_1_power15.sgrd",
formula = paste("a^", pow, sep=""))
Cheers
Alex
Alessandro wrote:
> Hi all,
>
>
>
> I need a suggestion to write this code in R more elegant . I have a DSM
> grid and I need to create a different grid raisin to different power.
>
>
>
>
>
> Thanx Ale
>
>
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^1.5)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power16.sgrd", formula = ~^1.6)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power17.sgrd", formula = ~^1.7)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power18.sgrd", formula = ~^1.8)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power19.sgrd", formula = ~^1.9)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^2.0)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power20.sgrd", formula = ~^2.1)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^2.2)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^2.3)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^2.4)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^2.5)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^1.6)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^2.7)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^2.8)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^2.9)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^3.0)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^3.1)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^3.2)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^3.3)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^3.4)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^3.5)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^3.6)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^3.7)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^3.8)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^3.9)
>
> rsaga.grid.calculus(in.grids = c("DSM_1.sgrd"),out.grid =
> "DCM_1_power15.sgrd", formula = ~^4.0)
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
--
Alexander Brenning
brenning at uwaterloo.ca - T +1-519-888-4567 ext 35783
Department of Geography and Environmental Management
University of Waterloo
200 University Ave. W - Waterloo, ON - Canada N2L 3G1
http://www.fes.uwaterloo.ca/geography/faculty/brenning/
More information about the R-sig-Geo
mailing list