英文:
How to refer to a column variable by its name?
问题
我的脚本如上所示,其中 `col` 是一个字符串变量。我如何使用列名(字符串变量)来引用列变量?我如何修改脚本以确保成功执行?
英文:
My script is as shown above, where col
is a string variable. How can I use the column names (string variables) to refer to column variables?How can I modify the script to ensure a successful execution?
答案1
得分: 1
根据上述脚本,我们可以推断您想要填充列中的空值。您可以使用nullFill
函数:
t = table(1.0 2.0 NULL 3.3 as open, NULL 1.3 NULL 2.2 as low)
nullFill(t, 0)
在tb_fj[col, <isNull(col)>]
中,col
必须是一个列变量,而不是一个字符串。您可以参考以下代码:
id = 1..10
x = rand(NULL 10.0, 10)
t = table(id, x as x1)
colName = `x1
t[colName, isNull(t[colName])] = 0
在其他情况下,您可以使用objByName
按名称返回一个变量,并使用funcByName
按名称执行一个函数。在SQL元编程中,您可以使用sqlCol
按名称返回一个列。
英文:
According to the above script, we can infer that you want to fill the NULL values in the column. You can use the nullFill
function:
t = table(1.0 2.0 NULL 3.3 as open, NULL 1.3 NULL 2.2 as low)
nullFill(t, 0)
In tb_fj[col, <isNull(col)>]
, col
must be a column variable, rather than a string. You can refer to the following code:
id = 1..10
x = rand(NULL 10.0, 10)
t  = table(id, x as x1)
colName=`x1
t[colName, isNull(t[colName])] = 0
In other cases, you can use objByName
to return a variable by its name, and funcByName
to execute a function by its name. In SQL metaprogramming, you can use sqlCol
to return a column by its name.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论