この関数があり、50 の異なるデータ セットで 50 回実行したいと考えています。毎回、4、18、20 行目のインデックスを変更する必要があります。(これらは、実行ごとに変更される唯一の引数です)。
1 myfunc <- function(file){
2 library(ncdf)
3 setwd("C:\\Users\\Desktop\\data")
4 AMS <- read.csv("C:\\Users\\Desktop\\data\\myarray.***index***.csv",header=FALSE)
5
6 xval <- seq(-124.5,-101.5,by=1)
7 yval <- seq(31.5,48.5,by=1)
8 nx <- length(xval)
9 ny <- length(yval)
10 data_temp <- array(NA, dim=c(nx,ny))
11 for( i in 1:nx ){
12 for( j in 1:ny ) {
13 data_temp[i,j] <- (AMS[i,j])
14 }
15 }
16 dimx <- dim.def.ncdf( "lon", "degreesE", xval,unlim=FALSE)
17 dimy <- dim.def.ncdf( "lat", "degreesN", yval,unlim=FALSE)
18 dimt <- dim.def.ncdf( "time", "year", ***index*** , unlim=TRUE)
19 vari <- var.def.ncdf("precipt", "mm/d", list(dimx,dimy,dimt),999999.999 )
20 ncnew <- create.ncdf( "output.***index***.nc", var )
21 put.var.ncdf( ncnew, vari,data_temp, start=c(1,1,1), count=c(nx,ny,1) )
22 close.ncdf(ncnew)
}
それを行う簡単な方法はありますか?