2016-12-03 105 views
0

我试图根据距离和方位从数据框中的第一点对位置点进行分类。此代码正在工作,但它只检查df$dist列的距离。R - 将数据帧剪成两列

df$circle_id = cut(df$dist, seq(0,41000000,1000), labels=FALSE, include.lowest=TRUE) 

我想要做的还是检查点的方位是否相同,只有它们可以放在同一个类别中。轴承储存在df$bearing

简单地说,我需要这两项业务合并为一个:

df$circle_id = cut(df$dist, seq(0,41000000,1000), include.lowest=TRUE) 
df$circle_id = cut(df$bearing, seq(-180,180,10), labels=FALSE, include.lowest=TRUE) 

的样本数据帧:

latitude longitude sensor_time circle_id segment_id weight  dist bearing 
1 48.15144 17.07569 1447149703   1   1  2 0.000000 -180.00000 
3 48.15404 17.07452 1447149743   3   1  1 302.422843 163.22826 
4 48.15277 17.07514 1447149762   2   1  1 153.179367 164.50437 
5 48.15208 17.07538 1447149771   1   1  1 74.666669 161.91792 
6 48.15461 17.07560 1447149773   3   1  3 353.106770 178.87100 
9 48.15139 17.07562 1447149811   1   1  2 7.828957 43.83916 

任何帮助表示赞赏, 谢谢

+2

设置'labels'参数。 – alistaire

回答

1

当您设置labels参数为FALSEcut函数将返回整数。举例:

> x <- sample(1:10) 
> cut(x, seq(0,10,2)) 
[1] (6,8] (8,10] (2,4] (4,6] (2,4] (0,2] (8,10] (0,2] (6,8] (4,6] 
Levels: (0,2] (2,4] (4,6] (6,8] (8,10] 
> cut(x, seq(0,10,2), labels = FALSE) 
[1] 4 5 2 3 2 1 5 1 4 3 
+0

是的,谢谢,我只是在等待,如果有人会知道如何解决问题的第一部分:) – ayshelina