단일 행에 대해 업데이트를 우아하게 수행하는 방법은 무엇입니까?안녕하세요 - 한 테이블에서 행을 가져와서 사용자가 입력 상자에 지정한 행에 있는 다른 테이블에 던지려고 합니다. 그러나 업데이트 함수에는 행을 지정하는 기능이 없는 것 같습니다. 따라서 두 데이터 테이블 모두에 대해 105개 열을 각각 입력하는 데 한 시간이 소요됩니다.
dt:{"ColA"}[rownumber] = dt1:{"ColA"}[1];<BR />dt:{"ColB"}[rownumber] = dt1:{"ColB"}[1];<BR />.<BR />.<BR />.<BR />dt:{"ColDA"}[rownumber] = dt1:{"ColDA"}[1];괜찮습니다. 하지만 코딩 친구들이 그 자리에서 몸부림치는 모습이 상상됩니다. 이를 수행하는 더 우아한 방법이 있습니까? 누군가 연관 배열을 참조하는 것을 본 적이 있지만 사용하는 데 문제가 있습니다.
위의 코드로 충분하다고 가정하지만 중요한 경우 관련 선이 빨간색으로 그려진 원본 코드는 다음과 같습니다.
w = New Window( "Choose Row Number for XRD Run input", // opens a window with a title and this content...
Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ), // window dressing
V List Box( // V and H lists nest to organize the display boxes
H Center Box( Text Box( "Choose Row Number for XRD Run input" ) ), // a second title, centered
Spacer Box( size( 1, 30 ) ), // a little vertical space
H Center Box( rowtemp=Number Edit Box( ) ), // data entry
Spacer Box( size( 1, 10 ) ), // a little vertical space
H Center Box( // center the button
Button Box( "Import Data", // this script runs when the button is pressed...
rownumber = rowtemp << Get;
// Run XML Import
Include( "jmpprj://contents/Import XRD XML.jsl");
// Reference Data Tables
dt = Data Table( "Experimental Info" );
dt1 = Data Table( "XMLTempTable" );
// Move to Experimental info table
<FONT color="#FF0000">dt:{"xsi:Schema Location 1"}[rownumber] = dt1:{"xsi:Schema Location 1"}[1];</FONT>
// Close XMLTempTable
close(dt1);
// optionally, close the dialog. Or, you might want to run it again...
w << closeWindow; // just the dialog, not the report
)
)
)
)
);자동화 및 스크립팅윈도우Re: 단일 행에 대해 업데이트를 우아하게 수행하는 방법은 무엇입니까?단일 행 업데이트를 수행하는 한 가지 방법은 다음과 같습니다.한 데이터 테이블에서 지정된 행을 가져와 다른 데이터 테이블의 지정된 행으로 업데이트합니다.
names default to here(1);
dt=
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
// Create a random data table with 5 rows
// Subset data table
// → Data Table( "Subset of Big Class" )
dt2 = dt << Subset( Sample Size( 5 ), Selected columns only( 0 ), output table("Selection") );
// Give new names to the subsetted table
dt2:name[1] = "PAT";
dt2:name[2] = "BRIT";
dt2:name[3] = "TERRY";
dt2:name[4] = "KRIS";
dt2:name[5] = "JEN";
wait(10);
// Below is the code that does the 1 row update
// Row in data table Big Class to be updated
outRow = 12;
// Row in data table Selection to get data from
inRow = 4;
// The Update process
// Create a row column in data table Big Class
dt << new column( "Row", formula(row()));
// Subset the inRow to a new table
dt2 << select where(row()== inRow);
dtTemp = dt2 << subset(selected rows(1), selected columns(0), invisible);
// Clear selected row in data table Selection
dt2 << clear select;
// Create a new column in the temp data table
dtTemp << new column("Row", set each value(outRow));
// Update data table Big Class
dt << Update(
With( dtTemp ),
Match Columns( :Row = :Row )
);
// Delete the temp data table
close( dtTemp, nosave );
// Delete the Row Column
dt << delete columns( :Row );
Re: 단일 행에 대해 업데이트를 우아하게 수행하는 방법은 무엇입니까?이름, 나이 등 두 테이블 모두에 고유 식별자가 있는 경우 이를 일치 조건으로 사용할 수 있습니다.
또한 가상 변환 열을 사용할 수 있습니다. 행 선택 업데이트할 행을 선택하기 위한 추가 일치 조건을 제공하려면 다음을 수행합니다.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Namespace(
"selection"
);
selection:ChangeRows = [5, 2, 7];
updateTable = dt << Subset( All rows, Selected columns only( 0 ) );
:weight << set each value( 1000 );
dt << Update(
With( updateTable ),
Match Columns(
:name = :name,
:age = :age,
transform column( "row selection", Formula( If( N Items( Loc( selection:ChangeRows, Row() ) ), 1, . ) ) ) =
transform column( "row selection", Formula( 1 ) )
),
Add Columns from Update Table( None ),
Replace Columns in Main Table( :weight )
);