简体   繁体   English

Excel DROP function 意外行为

[英]Excel DROP function unexpected behaviour

When getting a formula solution for this question Insert row to separates group of data with header I tried dropping the first and last row from a spill result.当获得此问题的公式解决方案时Insert row to separates group of data with header我尝试从溢出结果中删除第一行和最后一行。

This was the data used:这是使用的数据:

column A A列 column B B列 column C专栏 C
row 1第 1 行 pos位置 item物品 qty数量
row 2第 2 行 p1 p1 hat帽子 2 2个
row 3第 3 行 p3 p3 cap 3 3个

I started off with我开始了

=DROP( 
      REDUCE(0,ROW(A2:C3),LAMBDA(x,y,VSTACK(x,A1:C1,INDEX(A:C,y,),{"","",""}))),
      1)

This gave me the following spill:这给了我以下溢出: 在此处输入图像描述

I then wanted to not only drop the start value of the REDUCE function, but also the last line, which would always be blanks.然后我不仅要删除 REDUCE function 的起始值,还要删除最后一行,它总是空白。

For that I tried:为此,我尝试了:

=DROP( 
      REDUCE(0,ROW(A2:C3),LAMBDA(x,y,VSTACK(x,A1:C1,INDEX(A:C,y,),{"","",""}))),. 
      {1,-1})

I expected the {1,-1} array to pull it off ( 1 for it's first row and -1 for the last row).我希望{1,-1}数组能够将其拉下来(第一行为1 ,最后一行为-1 )。 This however resulted in:然而,这导致:

在此处输入图像描述

I couldn't understand this behaviour, so I tried it on a simpler range and or array:我无法理解这种行为,所以我在更简单的范围和/或数组上进行了尝试:

In A1 I used =SEQUENCE(3,3)A1中,我使用=SEQUENCE(3,3)

And I used =DROP(A1#,{1,-1}) which resulted in:我使用=DROP(A1#,{1,-1})结果是: 在此处输入图像描述

While doing the same directly: =DROP(SEQUENCE(3,3),{1,-1}) , gave another result:直接做同样的事情: =DROP(SEQUENCE(3,3),{1,-1}) ,给出了另一个结果: 在此处输入图像描述

And a bit funny: =DROP(SEQUENCE(3,3),{1,1,1,1,1}) Results in {4,4,4,4,4}有点滑稽: =DROP(SEQUENCE(3,3),{1,1,1,1,1})结果为{4,4,4,4,4}

I know I can use DROP twice to het the desired result, but I can't explain this behaviour.我知道我可以使用 DROP 两次来获得所需的结果,但我无法解释这种行为。

Is this because the first argument of the array alters the size of the array/range and Excel can't reference that from within the same calculation?这是因为数组的第一个参数改变了数组/范围的大小,而 Excel 不能在同一计算中引用它吗?

Another example of the new array functions exhibiting different behaviour when passed an array or a range .传递数组范围时表现出不同行为的新数组函数的另一个示例。

It appears that, in certain constructions, these functions behave like older functions such as OFFSET , in that, when passed a worksheet range, that range may need to first be ' dereferenced ' to an array.看起来,在某些结构中,这些函数的行为类似于OFFSET等旧函数,因为当传递工作表范围时,该范围可能需要首先“取消引用”到数组。

For example, with A1 containing =SEQUENCE(3,3) , as in your example, =DROP(A1#,{-1,1}) returns {#VALUE,,#VALUE!} .例如, A1包含=SEQUENCE(3,3) ,如您的示例所示, =DROP(A1#,{-1,1})返回{#VALUE,,#VALUE!}

However, ' dereferencing ' that range with, for example, N , ie =DROP(N(+A1#),{-1,1}) produces {1,4} , an identical result to =DROP(SEQUENCE(3,3),{1,-1}) .然而,'取消引用'范围,例如, N ,即=DROP(N(+A1#),{-1,1})产生{1,4} ,与=DROP(SEQUENCE(3,3),{1,-1})

As to the result of =DROP(SEQUENCE(3,3),{1,-1}) , I don't see how you could expect this to return {4,5,6} , since you are effectively asking it to simultaneously perform =DROP(SEQUENCE(3,3),1) , ie {4,5,6;7,8,9} and =DROP(SEQUENCE(3,3),-1) , ie {1,2,3;4,5,6} , which would require a third dimension, though Excel has never been capable of storing internal arrays of more than two dimensions.至于=DROP(SEQUENCE(3,3),{1,-1})的结果,我不明白你怎么能期望它返回{4,5,6} ,因为你实际上是在要求它同时执行=DROP(SEQUENCE(3,3),1) ,即{4,5,6;7,8,9}=DROP(SEQUENCE(3,3),-1) ,即{1,2,3;4,5,6} ,这将需要第三个维度,但 Excel 从未能够存储超过两个维度的内部 arrays 。 DROP 's second and third parameters are not designed to be used cumulatively when passed an array, if that was your intention. DROP的第二个和第三个参数不设计为在传递数组时累积使用,如果这是您的意图的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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