创建基于包含以下字母的新列。

huangapple go评论55阅读模式
英文:

Creating new column based on containing letter below

问题

我有一个数据集,看起来像下面这样:

Nickel	10
Nickel	U
Nickel	10
Nickel	U
Nickel	10
Nickel	U
Nickel	1.4
Nickel	J
Nickel	10
Nickel	U
Nickel	10
Nickel	U
Nickel	10
Nickel	U
Sodium	8.1
Sodium	7.4
Sodium	6.2
Sodium	7.6
Sodium	7.9
Sodium	6.9
Sodium	7.8
Sodium	8.9
Sodium	9
Sodium	7.9
Sodium	7
Sodium	R
Sodium	8.4
Sodium	7.7

一些行下面有与上面的数字对应的字符。例如:Nickel 10 U。我想要在有字符在下面的情况下添加另一列用于该字符。棘手的部分是,有些数值不对应字符(如果下面没有字符),这些数值需要保持为空白。

我可以创建一个代码来询问:如果有字符在数值下方,那么在相邻的列中添加字符。如果数值下面没有字符,将相邻列保留为空白。

英文:

I have a dataset that looks like the following:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

Nickel	10
Nickel	U
Nickel	10
Nickel	U
Nickel	10
Nickel	U
Nickel	1.4
Nickel	J
Nickel	10
Nickel	U
Nickel	10
Nickel	U
Nickel	10
Nickel	U
Sodium	8.1
Sodium	7.4
Sodium	6.2
Sodium	7.6
Sodium	7.9
Sodium	6.9
Sodium	7.8
Sodium	8.9
Sodium	9
Sodium	7.9
Sodium	7
Sodium	R
Sodium	8.4
Sodium	7.7

<!-- end snippet -->

Some rows have characters below it that correspond to the number above. Example: Nickel 10 U. I would like to add another column for the character IF a number has that character below it. The tricky part is, some are values do not correspond to a character (if there is not a character below) and those will need to remain blank.

Can I create a code that asks: if there is a character below a value, then add character in adjacent column. If there is no character below a value, leave the column adjacent blank.

答案1

得分: 0

=IF(ISTEXT(B2),B2,"")

这段代码检查B列下面的单元格。如果它是文本,就返回下面单元格中的文字。如果不是文本,就返回空白。你可以拖动这个公式来覆盖所有你的数据。

英文:
=IF(ISTEXT(B2),B2,&quot;&quot;)

This checks the cell beneath in column B. If it is text then it returns the letter in the cell beneath. If it is not text then it returns blank. You can drag the formula down to cover all of your data.

创建基于包含以下字母的新列。

答案2

得分: 0

数据移动

单个单元格(向下复制)

=IF(AND(ISNUMBER(B1),ISTEXT(B2)),B2,"")

数组公式(Microsoft 365中的溢出)

=IF(ISNUMBER(B1:B13)*ISTEXT(B2:B14),B2:B14,"")

吹毛求疵

  • 两个解决方案实际上都不准确,因为它们包括标题(B1)。
  • 将范围向下移动一行同样会包括数据下面的单元格(B15)。
  • 在Microsoft 365中,您可以通过使用VSTACKDROP获取向上移动的数据版本,然后可以将值进行逐一比较(参见E:F列)。
=LET(d,B2:B14,
    s,VSTACK(DROP(d,1),""),
IF(ISNUMBER(d)*ISTEXT(s),s,""))

创建基于包含以下字母的新列。

英文:

Shifting Data

Single Cell (Copy Down)

=IF(AND(ISNUMBER(B1),ISTEXT(B2)),B2,&quot;&quot;)

Array Formula (Spills in Microsoft 365)

=IF(ISNUMBER(B1:B13)*ISTEXT(B2:B14),B2:B14,&quot;&quot;)

创建基于包含以下字母的新列。

Nitpicking

  • Both solutions are actually inaccurate since they include the header (B1).
  • Shifting the ranges one row down will similarly include a cell below the data (B15).
  • In Microsoft 365, you can work around this by getting a version of the data shifted up by using VSTACK and DROP. Then you can compare the values side-by-side so to speak (see columns E:F).
=LET(d,B2:B14,
    s,VSTACK(DROP(d,1),&quot;&quot;),
IF(ISNUMBER(d)*ISTEXT(s),s,&quot;&quot;))

huangapple
  • 本文由 发表于 2023年4月6日 23:45:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951402.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定