gpt4 book ai didi

r - R中凸空间的交集

转载 作者:行者123 更新时间:2023-12-02 02:41:26 25 4
gpt4 key购买 nike

我有以下数据框:

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

最佳答案

我不确定代码是不是你想要的东西,其中使用了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

数据

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"))

关于r - R中凸空间的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59306507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com