【发布时间】:2019-04-04 12:53:29
【问题描述】:
我有一个包含 22 个点坐标的数据集(点代表鱼侧视图照片上的地标)。
我想测量这些点之间的 24 个距离(24 个不同的测量值)。例如点 1 和 5 之间的距离等等。
我想从中创建一个循环(总是会测量同一组 24 个距离 - 我有 2000 个这样的坐标列表,我必须测量这 24 个距离)。
我尝试了“dist”功能(见下文),它为我提供了所有点之间的所有可能测量值。
getwd()
setwd("C:/Users/jakub/merania")
LCmeasure <- read.csv("LC_meranie2.csv", sep = ";", dec = ",", header = T)
LCmeasure
head(LCmeasure)
names(LCmeasure)
> LCmeasure
point x y
1 1 1724.00000 1747.00000
2 2 1864.00000 1637.00000
3 3 1862.00000 1760.00000
4 4 2004.00000 1757.00000
5 5 2077.00000 1533.00000
6 6 2134.00000 1933.00000
7 7 2293.00000 1699.00000
8 8 2282.00000 1588.00000
9 9 2728.00000 1576.00000
10 10 2922.00000 1440.00000
11 11 3018.00000 1990.00000
12 12 3282.00000 1927.00000
13 13 3435.00000 1462.00000
14 14 3629.00000 1548.00000
15 15 3948.00000 1826.00000
16 16 3935.00000 1571.00000
17 17 4463.00000 1700.00000
18 18 4661.00000 1978.00000
19 19 4671.00000 1445.00000
20 20 4101.00000 1699.00000
21 21 2203.00000 2806.00000
22 22 4772.00000 2788.00000
df= data.frame(LCmeasure)
df
dflibrary(tidyverse)
dist(df[,-1])
Points <- data.frame(p1=c(1,1,1,3,4,5,1,1,1,7,10,10,11,12,12,14,15,11,13,7,20,20,20,1),p2=c(8,2,3,4,8,6,11,10,13,10,13,11,13,13,20,20,16,12,14,9,18,17,19,20))
Points
Dists <- Points %>% rowwise() %>% mutate(dist=dist(filter(LCmeasure, Point %in% c(p1,p2))))
Dists
现在我需要在 R 中指定只为我测量那些特定的 24 距离。例如在点 1 和 5 之间,然后在点 2 和 10 之间,以此类推。
并从中创建一个循环(始终是同一组测量的 24 个距离)。
【问题讨论】:
标签: r coordinates distance