简体   繁体   中英

Intersection of convex spaces in R

I have the following data frame:

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

The first column is an index. The first observation is characterised by 1 point, the second by 2 points.

I need to make the intersection of all combinations of observations, one way. The result creates a new dataframe with a new index, with again some observations that are characterised by 2 rows/points: 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"))

where 3 in the first column is the new observation created by intersecting the 2 former.

I though I could use pmin in each row but it does not work. Can somenone tackle this? 图表示

I am not sure if the code is the thing you want, where cummin() is used

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM