I need to find min year values in each group (grouping factor is ID). When there's only year values "0" in a group, the min result will be "0" but when there are other year values also (e.g. 1997, 0, 2002) then I need to omit the "0" and find the next min (in this example it would have been 1997, not 0).
我需要找到每组的最小年值(分组因子是ID)。当一个组中只有年份值“0”时,最小值将是“0”,但是当有其他年份值时(例如1997年、2002年),我需要省略“0”并找到下一个最小值(在本例中,它应该是1997年,而不是0)。
For example if I have this data:
例如,如果我有这个数据:
ID year
170946 1960
170946 1960
170950 0
170950 0
170952 1905
435041 1990
435041 1995
435046 0
435046 1995
435046 2002
Then I want that the new column would look like this:
那么,我希望新的专栏是这样的:
ID year MIN
170946 1960 1960
170946 1960 1960
170950 0 0
170950 0 0
170952 1905 1905
435041 1990 1990
435041 1995 1990
435046 0 1995
435046 1995 1995
435046 2002 1995
Could someone help me please?
有人能帮我吗?
2 个解决方案
#1
#2
0
You must use a array formula with IF
, MIN
and SMALL
, like this:
你必须使用一个数组公式,如果,最小和最小,像这样:
=SMALL(IF(A:A=A2,B:B),IF(MIN(IF(A:A=A2,B:B))=0,2,1))
Attempt to press Ctrl + Shift + Enter
instead of a single Enter
.
尝试按Ctrl + Shift + Enter键而不是一个Enter键。
#1
1
You can use this array formula in C2
你可以在C2中使用这个数组公式
=MIN(IF(A$2:A$100=A2,IF(B$2:B$100<>0,B$2:B$100)))
= MIN(如果(2美元:100美元= A2,如果(B 2美元:100美元< > 0,B 2美元:B 100美元)))
confirm with CTRL+SHIFT+ENTER
and copy down
确认并按CTRL+SHIFT+回车
see below
见下文
#2
0
You must use a array formula with IF
, MIN
and SMALL
, like this:
你必须使用一个数组公式,如果,最小和最小,像这样:
=SMALL(IF(A:A=A2,B:B),IF(MIN(IF(A:A=A2,B:B))=0,2,1))
Attempt to press Ctrl + Shift + Enter
instead of a single Enter
.
尝试按Ctrl + Shift + Enter键而不是一个Enter键。