0

我试图避免手动运行 ~250 克拉克和埃文斯测试 (clarkevans.test)。

我在 excel 文件中有一个 xmin、xmax、ymin、ymax 坐标表,其中每一行都是操作窗口的尺寸。

在将 excel 文件 (read.csv) 读入 RI 后,似乎无法获得任何形式的“应用”和“owin”来协同工作以为每一行输出一个 owin。最终我需要创建 ppp 并以类似的方式运行 clarkevans.test,但现在我只需要第一步的帮助。

coordin<-read.csv("Coordin.csv")
cdf<-data.frame(coordin)
> cdf
      xmin   xmax    ymin    ymax
1   456741 456841 3913505 3913605
2   453341 453441 3915805 3915905
3   453441 453541 3915805 3915905
4   452441 452541 3915705 3915805
5   453741 453841 3915705 3915805

我已经尝试了几种变体,但我无法得到任何工作。

lapply(cdf, function(x) owin(xmin, xmax, ymin, ymax)) 
4

2 回答 2

0

我会为此推荐一个 for 循环,因为您可以轻松地添加步骤来生成ppp对象,当您到达那一步时:

library(spatstat)
# Test data:
dat <- data.frame(xmin = 1:3, xmax = 2:4, ymin = 1:3, ymax = 2:4)
# List of owin initialised as unit squares:
win_list <- replicate(nrow(dat), owin(), simplify = FALSE)
# For loop to make each owin:
for(i in seq_len(nrow(dat))){
  # Vector of owin values:
  v <- as.numeric(dat[i, ])
  # Finally create the owin object
  win_list[[i]] <- owin( v[1:2], v[3:4])
}

然后owin对象列表包含您所期望的内容:

win_list
#> [[1]]
#> window: rectangle = [1, 2] x [1, 2] units
#> 
#> [[2]]
#> window: rectangle = [2, 3] x [2, 3] units
#> 
#> [[3]]
#> window: rectangle = [3, 4] x [3, 4] units

如果你坚持使用 apply:

apply(dat, 1, function(x) owin(c(x[1], x[2]), c(x[3], x[4])))
#> [[1]]
#> window: rectangle = [1, 2] x [1, 2] units
#> 
#> [[2]]
#> window: rectangle = [2, 3] x [2, 3] units
#> 
#> [[3]]
#> window: rectangle = [3, 4] x [3, 4] units
于 2016-10-11T08:26:19.090 回答
0

原始代码不起作用,因为调用owin(xmin,xmax,ymin,ymax)语法无效owin

一种有效的语法是owin(c(xmin,xmax), c(ymin,ymax)).

以下将适用于其列为的数据dfxmin,xmax,ymin,ymax

apply(df, 1, function(z) owin(z[1:2], z[3:4])
于 2016-10-12T01:39:38.813 回答