R中凸空间的交集

问题描述 投票:1回答:1

我有以下数据框:

structure(list(C1 = c(1, 2, 2, 3, 4, 5, 5, 6), C2 = c(3.5, 3, 
2.5, 2, 3, 2, 3, 5), C3 = c(6.5, 8, 9, 5, 7, 4, 3, 6)), row.names = c(NA, 
-8L), class = c("tbl_df", "tbl", "data.frame"))

第一列是一个索引。第一个观察点的特征是1点,第二个观察点的特征是2点。

我需要以一种方式将所有观察值组合起来。结果将创建一个具有新索引的新数据框,并具有一些以2行/点为特征的观察值:1-2、1-3、1-4、1-5、1-6、2-3、2- 4、2-5、2-6、3-4、3-5、3-6、4-5、4-6、5-6:

df2 = structure(list(C1 = c(1, 2, 3, 4, 4, 5, 6,7, 8, 8, 9, 10, 11, 11, 12, 13, 13, 14, 15, 15), C2 = c(3,2,3,3,2,3.5,2,3,2,3,3,2,3,2,2,2,3,3,2,3), C3 = c(6.5,5,6.5,3,4,6,5,7,4,3,6,5,3,4,5,4,3,6,4,3)), row.names = c(NA, 
                                                                                                                         -20L), class = c("tbl_df", "tbl", "data.frame"))

其中第一列中的3是通过与前2个相交而创建的新观测值。

尽管我可以在每行中使用pmin,但它不起作用。有人可以解决吗?graph representation

r intersection
1个回答
1
投票

我不确定代码是否是您想要的东西,使用cummin()的地方

df2 <- cbind(df[1],cummin(df[-1]))
> df2
  C1  C2  C3
1  1 3.5 6.5
2  2 3.0 6.5
3  2 2.5 6.5
4  3 2.0 5.0
5  4 2.0 5.0
6  5 2.0 4.0
7  5 2.0 3.0
8  6 2.0 3.0

DATA

df <- structure(list(C1 = c(1, 2, 2, 3, 4, 5, 5, 6), C2 = c(3.5, 3, 
2.5, 2, 3, 2, 3, 5), C3 = c(6.5, 8, 9, 5, 7, 4, 3, 6)), row.names = c(NA, 
-8L), class = c("tbl_df", "tbl", "data.frame"))
© www.soinside.com 2019 - 2024. All rights reserved.