I have a data frame with 3 variables (A, B and C), variables A and B refer to a product and variable C refers to the time it takes to change the production between variable A and B.
Variables A and B contain a list of manufacturing products where it is possible to present different combinations with the same product. I want to build a code that allows me to enter n specific products and this will show me the combinations that have a shorter production change time.
I have tried to test with a data.table but I can't think of where else to continue, I greatly appreciate your help.
Greetings.
It sounds like your data frame looks a bit like this one:
products <- c("Widgets", "Bebbits", "Foobars")
df <- expand.grid(products, products)
df <- setNames(df[df[[1]] != df[[2]],], c("A", "B"))
df$C <- c(5, 2, 5, 1, 6, 7)
df
#> A B C
#> 2 Bebbits Widgets 5
#> 3 Foobars Widgets 2
#> 4 Widgets Bebbits 5
#> 6 Foobars Bebbits 1
#> 7 Widgets Foobars 6
#> 8 Bebbits Foobars 7
If you want to know which products are below a certain threshold, you could do:
threshold <- 3
df[df$C < threshold, ]
#> A B C
#> 3 Foobars Widgets 2
#> 6 Foobars Bebbits 1
And if you wanted a particular quantile (say the shortest 10%) you would do:
threshold <- quantile(df$C, 0.1)
df[df$C < threshold, ]
#> A B C
#> 6 Foobars Bebbits 1
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.