简体   繁体   中英

Looping an IDW function in R

I am kind of new to R and I would like to test different parameters to perform an Inverse Distance Weighting (IDW) interpolation.

data.idw.n <- idw(variable~1, data, data.grid, nmax=n)

I would like to repeat the following function several times, by just changing the n value (let's say from 1 to 20 ) of the nmax variable and store the results separately to perform a model sensibility analysis.

I think i would need some kind of basic looping. Can someone help me?

Many thanks!

For this I would use mapply :

list_of_idw_results = mapply(idw, 
                             nmax = 1:20, 
                             MoreArgs = list(formula = variable ~ 1, 
                                             data = data, 
                                             newdata = data.grid)) 

This leads to a list of idw results, for nmax values from 1 to 20. You can vary more variables at the same time by adding more variables after nmax = 20 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM