Arrays 为什么当脚本的各个部分自己工作正常时,我会遇到与不匹配对象长度相关的错误?

Arrays 为什么当脚本的各个部分自己工作正常时,我会遇到与不匹配对象长度相关的错误?,arrays,r,matrix,Arrays,R,Matrix,我有一个脚本来处理天气极地雷达数据到笛卡尔坐标系,然后绘制它。我已经测试了每个单独的组件,每个组件每次都做了它们应该做的事情。最近,我需要简化所有内容,因此我将其放在脚本中,但当我尝试在其中运行数据时,会弹出一条我不完全理解的错误消息。任何帮助都将不胜感激。提前谢谢。我正在使用命令radProcesstest,1,ref执行脚本 我的数据看起来是这样的,尽管这个例子已经从它所在的3600x800数据帧缩小了- V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 1

我有一个脚本来处理天气极地雷达数据到笛卡尔坐标系,然后绘制它。我已经测试了每个单独的组件,每个组件每次都做了它们应该做的事情。最近,我需要简化所有内容,因此我将其放在脚本中,但当我尝试在其中运行数据时,会弹出一条我不完全理解的错误消息。任何帮助都将不胜感激。提前谢谢。我正在使用命令radProcesstest,1,ref执行脚本

我的数据看起来是这样的,尽管这个例子已经从它所在的3600x800数据帧缩小了-

     V1  V2  V3  V4 V5 V6 V7 V8 V9 V10
1   -96 -75 -69 -62 51 40 47 50 52  47
2   -94 -80 -67 -57 53 37 44 51 54  50
3  -100 -81 -72 -61 54 42 50 48 56  50
4  -101 -82 -72 -63 55 43 40 47 50  48
5  -999 -78 -73 -59 55 40 46 49 54  54
6  -102 -81 -71 -59 51 37 44 52 55  57
7  -101 -79 -74 -59 54 43 42 47 55  47
8   -95 -80 -73 -59 52 40 48 54 58  54
9   -96 -78 -75 -58 57 44 39 50 47  55
10  -99 -79 -73 -59 57 45 46 56 55  53
当我尝试运行数据时,遇到一条错误消息,如下所示-

Error in radProcess(test, 10, ref) : 
dims [product 864000] do not match the length of object [2880000]
In addition: Warning message:
In final.levl[cbind(z.rad, t.rad, r.rad)] * conversion.factor :
longer object length is not a multiple of shorter object length
下面可以看到脚本-

radProcess <- function(file, level, product){

   ## Convert file to 3 dimensional array format organized ##
   ## by scan level (10-top, 1-bottom of array) ##
   print("Converting to 3D Array")
   x.arr.vert <- array(unlist(file), dim = c(10,360,800))
   x.arr.horz <- aperm(array(x.arr.vert, dim = c(360,10,800)), c(2,1,3))
   final.levl <- x.arr.horz[ c(10:1),,]

      ## Create matrix of coordinates and values and then ## 
      ## converts from polar to cartesian coordinates ##

      print("Creating Matrix of Polar Coordinates")
      mat <- which( (final.levl > -1000), arr.ind = TRUE)

      z.rad <- mat[, 1]
      t.rad <- mat[, 2]
      r.rad <- mat[, 3]

        print("Converting to Cartesian Coordinates")
        theta.polar <- t.rad * pi / 180
        r.polar <-  r.rad * 0.075
        x.cart <- r.polar * cos(theta.polar)
        y.cart <- r.polar * sin(theta.polar)

        ## Reflectivity adjustment constant = .514245 ##
        ## Velocity adjustment constant = .1275628 ##

  print("Determining Conversion Factor")
  conversion.factor <- ifelse( (product == "ref"), yes = .514245, no = .1275628)

    print("Copying Values from Array to Matrix")
            value  <- (final.levl[cbind(z.rad, t.rad, r.rad)] * conversion.factor)
    Cart.Coord.Matrix <- matrix( NA, nrow = 2880000, ncol = 4)
            Cart.Coord.Matrix <- cbind(z.rad, y.cart, x.cart, value)

## Create new matrix level wanted from transposed value matrix ##i

print("Reducing down to Level Wanted")
specified.level <- Cart.Coord.Matrix[z.rad == level,]

## Plot level values in Radar plot ##

print("Plotting Data Points")
x1<-specified.level[,3]
y2<-specified.level[,2]
z3<-specified.level[,4]
d1 <- data.frame(x1,y2,z3)
dg1 <-qplot(y2,x1,colour=z3,data=d1)
dg1 + scale_colour_gradientn(limits = c(0, 60), colours = rev(rainbow(10)))
}
成品实例

您的参考向量似乎有864000条记录,而不是2880000条,因此R无法执行final。levl[cbindz.rad,t.rad,R.rad]*conversion.factorA函数的示例输入将非常有用,这样我们就可以完全重现您遇到的情况。另外,您的脚本中缺少一个}。谢谢。我认为丢失的}是一个副本和过去的错误。脚本的示例输入是-radProcesstest,1,ref