从文件存储变量并在 jsl 脚本中使用 for max 函数你好成员,
我是刚开始编写 JSL 脚本的新用户,您能否提供如何执行以下需要的建议
我有 2 个文件,
File1 :包含具有数千列(字符串)和行(数字)的数据
File2:包含一些我手动创建的列列表,用于从 file1 中选择感兴趣的列
我需要根据文件 2 中的列表执行 max 函数并在文件 1 中创建新列
下面是我尝试过但没有按预期工作的代码。
dt = 打开 ("C:/File2.csv")
列表 = dt << 获取名称; // list = 基本上是来自 file1 = row 1、row2、row10 等的几个随机列名
dt1 = 打开(“C:/File1.jmp”)
新列 ("max list",Numeric,Formula (Max (list)));
数据表脚本回复:从文件存储变量并在 jsl 脚本中使用 for max 函数不确定您的数据是什么样的,但这是一个建议。 不是最简单的解决方案,需要 JMP16+
Names Default To Here(1);
dt = New Table("File2",
Add Rows(0),
Compress File When Saved(1),
New Column("Column 1", Character, "Nominal", Format("Best", 12), Set Values({"Column 1", "Column 2"}))
);
dt1 = New Table("File1",
Add Rows(3),
Compress File When Saved(1),
New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([1, 1, 1])),
New Column("Column 2", Numeric, "Continuous", Format("Best", 12), Set Values([2, 2, 2])),
New Column("Column 3", Numeric, "Continuous", Format("Best", 12), Set Values([3, 3, 3]))
);
Show(dt << Get Name); // this will get name of the datatable not columns
max_list = Column(dt, "Column 1") << get values;
expr_max = Expr(Max());
For Each({col}, max_list,
Insert Into(expr_max, NameExpr(AsColumn(Column(dt1, col))))
);
Show(NameExpr(expr_max));
Eval(EvalExpr(
dt1 << New Column("MaxList", Numeric, Continuous, Formula(
Expr(NameExpr(expr_max))
));
));
使用 Eval Insert、Eval Expr、Parse 和 Substitute 将一个表达式插入另一个表达式为了好好读书
回复:从文件存储变量并在 jsl 脚本中使用 max 函数非常感谢你,特克斯尼尔森,
有效 。犯了一个简单的错误,没有在 file2 中使用列名 Maxlist
但我收到另一个错误:命名空间“office1.close:today”未定义返回参数中的最大值或列表参数的单个矩阵中的值
“office1.close:today”是 file2 之一
如果我打开 file1 maxlist 列并单击编辑公式,错误就会消失。
回复:从文件存储变量并在 jsl 脚本中使用 max 函数我再次查看了您最新的帖子,我相信我有一个新脚本可以解决您在该帖子中暴露的复杂名称问题。
// The code below this line is the that does the calculations The code above this line would
// not normally be included
Names Default To Here( 1 );
// point to the large data table with lots of rows and columns
dt = Data Table( "Main" );
// If you are opening the table from a folder, this statement would be
// dt = open("the path to the table");
// point to the second data table that contains a list of columns to be summed
dtMax = Data Table( "config" );
// If you are opening the table from a folder, this statement would be
// dtMax = open("the path to the table");
// Just added a short pause so one can see the original tables before changing
// Create the new columns
For( i = 1, i <= N Cols( dtMax ), i++,
sumList = Column( dtMax, i ) << get values;
dt << New Column( Column( dtMax, i ) << get name );
nameList = ":\!"" || sumList[1] || "\!"n";
For( k = 2, k <= N Rows( dtMax ), k++,
Insert Into( nameList, ", :\!"" || sumList[k] || "\!"n" )
);
Column( dt, N Cols( dt ) ) << set formula( Eval( Parse( "max(" || nameList || ")" ) ) );
);回复:存储文件中的变量并在 jsl 脚本中使用 max 函数
谢谢你的建议,它没有像预期的那样工作,我可能做错了什么。为了更清楚,我提供了文件的外观和要求
file1 看起来像这样(这是我的主表,我想从 office1,2,4 中找到最大值)
| 办公室1 | 办公室2 | 办公室3 | 办公室4 | 办公室 5 |
| 2 | 3 | 0 | 6 | 1 |
| 3 | 2 | 6 | 4 | 4 |
| 2 | 5 | 3 | 2 | 3 |
| 1 | 0 | 2 | 3 | 2 |
| 4 | 1 | 2 | 7 | 1 |
| | | | | |
预期输出新列Maxlist(值来自 office1,2,4)
简单的解决方案:新列(“MaxList”,数字,连续,公式(Max(:“office1”,:“office2,:“office4”)));
| 办公室1 | 办公室2 | 办公室3 | 办公室4 | 办公室 5 | .. | 最大列表 | | |
| 2 | 3 | 0 | 6 | 1 | | 6 | | |
| 3 | 2 | 6 | 4 | 4 | | 4 | | |
| 2 | 5 | 3 | 2 | 3 | | 5 | | |
| 1 | 0 | 2 | 3 | 2 | | 3 | | |
| 4 | 1 | 2 | 7 | 1 | | 7 | | |
| | | | | | | | | |
由于我的 maxlist 每天都会变化,因此我想使用另一个 file2 作为 max list 的输入参数
file2:作为输入参数给出的列名列表并执行脚本
寻找解决方案,我可以在文件2中给出最大列表并在文件1中执行
新列(“MaxList”,数字,连续,公式(Max(基于file2 列表”)));