使用for循环进行数据过滤的问题大家好
我现在有问题来过滤掉数据。我有两个问题:
问题1 :我如何将@转换成字符?因为当我运行脚本时,它会出错。
组(
:名称(“I_P2A .6 / .045 Avg @ ET”),
:名称(“I_N2A .3 / .045 Avg @ ET”),
:名称(“I_P2G_G_0.6 / 0.06 Avg @ ET”),
:名称(“I_P2HG_0.6 / 0.06 Avg @ ET”)
)
频率(“无”),
重量(“无”)
问题2: 数据通过循环过滤。
如果我想将下面的4个参数分组为一个名称(声明名称),是否有可能?
因为在我的数据集中,列名如下:I_P2A .6 / .045 Avg @ ET
I_N2A .3 / .045 Avg @ ET
I_P2G_G_0.6 / 0.06 Avg @ ET
I_P2HG_0.6 / 0.06 Avg @ ET
所以,我的目的是如何将4列写成一个名称,因为当我写出脚本时,我只需要编写我声明的变量名称(4个参数),然后它会自动知道这4个参数在里面这个变量名。可以分成一个名字吗?
dt = open("---------");
family_device = Data Table("--------") << Summary (Group(:Family Device), Freq("None"), Weight("None"));
parameter = Data Table("---------") << Summary(
Group(
:Name( "I_P2A .6/.045 Avg @ ET" ),
:Name( "I_N2A .3/.045 Avg @ ET" ),
:Name( "I_P2G_G_0.6/0.06 @ ET" ),
:Name( "I_P2HG_0.6/0.06 @ ET" )
),
Freq( "None" ),
Weight( "None" )
);
For(ifamily_device = 1, ifamily_device <= NRows(family_devices), ifamily_device++,
thisFamily_Device = family_devices : Family Device[ifamily_device];
For(iparameter = 1, iparameter <= Nrows(parameters), iparameter++,
thisParameter = parameters: (column name in dataset-how i convert all these 4 parameters into one group name?)[iparameter];
Group(
:Name( "I_P2A .6/.045 Avg @ ET" ),
:Name( "I_N2A .3/.045 Avg @ ET" ),
:Name( "I_P2G_G_0.6/0.06 Avg @ ET" ),
:Name( "I_P2HG_0.6/0.06 Avg @ ET" )
)
);
);谢谢。
Re:使用for循环进行数据过滤的问题
Re:使用for循环进行数据过滤的问题我想我可能会更好地使用这张照片。
现在假设我有S_GX,它使用参数I_P2A GSVT .6 / .045 Avg和I_N2A GSVT .3 / .045 Avg。但是现在我需要从我的数据集中总结出来,这意味着我需要总结S_GX将使用两个参数,即我 _P2A GSVT .6 / .045 Avg和I_N2A GSVT .3 / .045 Avg.etc ...
谢谢
Re:使用for循环进行数据过滤的问题很抱歉没有清楚解释我想做什么。
实际上我想做的是,我想根据产品类型进行总结,例如:现在我有产品a,b,c,d,e,每个产品都有自己的参数列表,例如:I_P2A。6 / .045 Avg @ ET,I_N2A .3 / .045 Avg @ ET,I_P2G_G_0.6 / 0.06 Avg @ ET,I_P2HG_0.6 / 0.06 Avg @ ET等 所以现在我想做过滤器或者可能使用选择匹配的单元格来完成产品的总结,使用I_P2A .6 / .045 Avg @ ET,产品b使用I_N2A .3 / .045 Avg @ ET等。并且每个产品都有多个参数。因为在那之后我需要根据结果来做图表。然后我的数据相当多,所以我需要在进行变异性图表之前对数据进行子集化。现在我的条件是我不知道如何编写脚本来进行我解释的总结。我也不能硬编码。
那么,你能给我一些建议吗?
谢谢Re:使用for循环进行数据过滤的问题似乎我不明白你想要什么。 也许某人有更好的洞察力。
Re:使用for循环进行数据过滤的问题我提出的一个问题:
根据您的代码,为什么我们需要设置列名(重命名列)?因为在我的情况下,列的名称如:(I_P2A .6 / .045 Avg @ ET,I_N2A .3 / .045 Avg @ ET,I_P2G_G_0.6 / 0.06 Avg @ ET,I_P2HG_0.6 / 0.06 Avg @ ET-I仍然需要它作为我的列名称),我的问题是如何将4个不同的列名称组成一个名称,以便我在下面的代码中轻松声明。
因为最后,我需要根据家庭设备和参数进行总结(4个不同的列名)
谢谢。Re:使用for循环进行数据过滤的问题代码中的错误是在JSL中运行太多步骤的症状,因此您对哪些问题导致哪些问题感到困惑。 JSL提供了一些很棒的东西来帮助您逐步完成代码以查看真正的问题。 首先是突出显示代码的任何部分,并仅运行突出显示的代码。 只是将鼠标悬停在一个变量上并看看它的最后一个值是什么。 更正式的环境是使用JSL调试器,它将允许您逐行执行代码以验证逻辑和计算。
以下是对您提供的代码的评估。 您将看到的是,代码中的错误来自于对变量名称的不够谨慎。
// This line of code has nothing to do with the script, so I have commented it out
//dt = open("---------");
// For testing purposes,a data table needs to be opened and setup with the columns used in the script
// Open the Big Class data table
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
// Now modify the data table to make it look like the script wants
// Delete the "name" column
dt << delete columns( "name" );
// The "sex" column will become the "Family Device" column
dt:sex << set name( "Family Device" );
// The "age", "weight", and "height" columns will be changed to three of the other columns required
dt:age << set name( "I_P2A .6/.045 Avg @ ET" );
dt:height << set name( "I_N2A .3/.045 Avg @ ET" );
dt:weight << set name( "I_P2G_G_0.6/0.06 @ ET" );
// Create the final column as a simple formula column
dt << New Column( "I_P2HG_0.6/0.06 @ ET", formula( Random Normal() ) );
// Now just remove the formula to make the values static(just a simple step to make the table clea)n
dt:Name( "I_P2HG_0.6/0.06 @ ET" ) << delete property( "Formula" );
// The sample data table is complete
// Now run the script
// The creation of the first summary data table....only the data table's name was substituted
// The summary works without error
family_device = Data Table( "Big Class" ) << Summary( Group( :Family Device ), Freq( "None" ), Weight( "None" ) );
// The creation of the second summary data table....once again only the data table name was changed
// There is no issue with the "@" being in the column names
// The summary works without error
parameter = Data Table( "Big Class" ) << Summary(
Group( :Name( "I_P2A .6/.045 Avg @ ET" ), :Name( "I_N2A .3/.045 Avg @ ET" ), :Name( "I_P2G_G_0.6/0.06 @ ET" ), :Name( "I_P2HG_0.6/0.06 @ ET" ) ),
Freq( "None" ),
Weight( "None" )
);
// There are issues here. The first one is that in the "NRows()" function, a variable by the
// name of "family_devices" is used, and there is not a variable by that name. The name of
// the variable is "family_device". When this code is run, that error is clearly listed in the Log
//For(ifamily_device = 1, ifamily_device <= NRows(family_devices), ifamily_device++,
For( ifamily_device = 1, ifamily_device <= N Rows( family_device ), ifamily_device++,
// Once again the reference to "family_device" is made
//thisFamily_Device = family_devices : Family Device[ifamily_device];
thisFamily_Device = family_device:Family Device[ifamily_device];
// For a third time, an invalid variable name has been specified. In this case, "Parameters"
// instead of "parameter"
//For(iparameter = 1, iparameter <= Nrows(parameters), iparameter++,
For( iparameter = 1, iparameter <= N Rows( parameter ), iparameter++,
// I am a bit confused on this one. First off, "parameters" instead of "parameter" is used, however
// the grouping question could be interpreted a couple of ways, so what I have done is to just
// concatenate the columns together
/*thisParameter = parameters: (column name in dataset-how i convert all these 4 parameters into one group name?)[iparameter];
Group(
:Name( "I_P2A .6/.045 Avg @ ET" ),
:Name( "I_N2A .3/.045 Avg @ ET" ),
:Name( "I_P2G_G_0.6/0.06 Avg @ ET" ),
:Name( "I_P2HG_0.6/0.06 Avg @ ET" )
)*/
thisParameter = Char( parameter:Name( "I_P2A .6/.045 Avg @ ET" )[iparameter] ) || Char( parameter:Name( "I_N2A .3/.045 Avg @ ET" )[iparameter] ) ||
Char( parameter:Name( "I_P2G_G_0.6/0.06 @ ET" )[iparameter] ) || Char( parameter:Name( "I_P2HG_0.6/0.06 @ ET" )[iparameter] );
show(thisFamily_Device, thisParameter );
);
);