使用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 );
);
);