I think the issue was by ths following , I cannot guarantee whether this is a solution efficient enough for your working data, but this is what I would try first: code :
m1 < as.matrix(dt[, grep('^t', names(dt)), with = FALSE])
m2 < as.matrix(dt[, grep('^p', names(dt)), with = FALSE])
t_min < apply(m1, 1, min, na.rm = TRUE)
t_min[is.infinite(t_min)] < NA_real_
p_min_index < rep(NA_integer_, length(t_min))
p_min_index[!is.na(t_min)] < apply(m1[!is.na(t_min), ], 1, which.min)
dt[, t_min := t_min]
dt[, p_min := m2[cbind(seq_len(nrow(m2)), p_min_index)] ]
dt[, p_min_col := grep('^p', names(dt), value = TRUE)[p_min_index] ]
# p1 p2 p3 t1 t2 t3 t_min p_min p_min_col
# 1: a b z 1 7 8 1 a p1
# 2: b c x 2 6 3 2 b p1
# 3: c d <NA> 3 5 NA 3 c p1
# 4: d a <NA> NA NA NA NA <NA> <NA>
# 5: e f y 5 3 2 2 y p3
# 6: f g <NA> 6 2 NA 2 g p2
# 7: g h s 7 NA 1 1 s p3
Share :

How to find minimum and maximum values in Column B based on a specific string in column A?
By : Bdbf
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have a list of items in Column A and have corresponding year and month values in Column B and C respectively. I am looking to find the minimum and maximum year in Column B (based on specific value in Column A), then find the corresponding month in Column C (only for max and min value) and then generate and fill in a Start and End date in Column E and F respectively. E.g. IF @Item = Laptop THEN FIND MIN,MAX of @YEAR and THEN FIND adjacent value in @Month. Finally formulate and display a date accordingly. Could i achieve this using a formula or is it out of scope and is better achieved using a macro? , For the Start date, in E2: code :
=IF(A2<>A1,DATE(AGGREGATE(15,6,$B$1:$B$1000/($A$1:$A$1000=A2),1),AGGREGATE(15,6,$C$1:$C$1000/(($A$1:$A$1000=A2)*($B$1:$B$1000 = AGGREGATE(15,6,$B$1:$B$1000/($A$1:$A$1000=A2),1))),1),1),"")
=IF(A2<>A1,EOMONTH(DATE(AGGREGATE(14,6,$B$1:$B$1000/($A$1:$A$1000=A2),1),AGGREGATE(14,6,$C$1:$C$1000/(($A$1:$A$1000=A2)*($B$1:$B$1000 = AGGREGATE(14,6,$B$1:$B$1000/($A$1:$A$1000=A2),1))),1),1),0),"")
=IF(A2<>A1,AGGREGATE(15,6,DATE($B$1:$B$1000,$C$1:$C$1000,1)/($A$1:$A$1000=A2),1),"")
=IF(A2<>A1,AGGREGATE(14,6,EOMONTH(DATE($B$1:$B$1000,$C$1:$C$1000,1),0)/($A$1:$A$1000=A2),1),"")

how to read a text file column by column and find the minimum value in every column
By : Rubel Mahmud
Date : March 29 2020, 07:55 AM
may help you . In general, common tasks are often automated / optimised via libraries. The below code uses the numpy library to process your task: code :
import numpy as np
arr = np.genfromtxt('file.txt', delimiter=',')
arr_colmin = arr.min(axis=0)

using sparksql and spark dataframe How can we find the COLUMN NAME based on the minimum value in a row
By : Pushkar Deodhar
Date : March 29 2020, 07:55 AM
Hope that helps i have a dataframe df . its having 4 columns , you can do something like, code :
import org.apache.spark.sql.functions._
val cols = df.columns
val u1 = udf((s: Seq[Int]) => cols(s.zipWithIndex.min._2))
df.withColumn("res", u1(array("*")))

Arrayformula to pull the minimum value in a column based on cell contents of another column
By : user2886777
Date : March 29 2020, 07:55 AM
this one helps. I'm trying to find a way to get my minifs formula to work in an arrayformula in google sheets. code :
=ARRAYFORMULA(TO_DATE(IFERROR(VLOOKUP(A2:A,
SORT(QUERY(Data!A2:C, "where B = 'Departure'"), 1, 1, 3, 1), 3, 0))))

How to find minimum value in a column based on condition in an another column of a dataframe?
By : Jaryt23
Date : March 29 2020, 07:55 AM
I wish this help you I have a dataframe like below: , If possible value 15 is not in data, use general solution: code :
df = df.reset_index(drop=True)
out = df.loc[df.Req.eq(15)[::1].cumsum().ne(0), 'Response'].sort_values()
print (out)
1 0
3 3
2 4
0 6
Name: Response, dtype: int64
print (next(iter(out), 'no match'))
0
print (df.Req.eq(15))
0 False
1 False
2 False
3 True
4 False
Name: Req, dtype: bool
print (df.Req.eq(15)[::1])
4 False
3 True
2 False
1 False
0 False
Name: Req, dtype: bool
print (df.Req.eq(15)[::1].cumsum())
4 0
3 1
2 1
1 1
0 1
Name: Req, dtype: int32
print (df.Req.eq(15)[::1].cumsum().ne(0))
4 False
3 True
2 True
1 True
0 True
Name: Req, dtype: bool
print (df)
Number Req Response
0 0 3 6
1 1 5 0
2 2 33 4
3 3 150 3
4 4 12 2
df = df.reset_index(drop=True)
out = df.loc[df.Req.eq(15)[::1].cumsum().ne(0), 'Response'].sort_values()
print (out)
Series([], Name: Response, dtype: int64)
print (next(iter(out), 'no match'))
no match

