숫자로 시작하는 열 이름열 이름에 숫자 이니셜이 있어서 해당 이름이 날짜를 나타내는 것으로 인식하는 코드가 있습니다. 문제를 해결하기 위해 열 이름을 변경했지만 보기 좋지 않습니다. 또한 이름을 나타내는 객체를 Char(obj) 문으로 감싸는 것도 효과가 없었습니다. 이 문제를 더 잘 해결할 수 있는 방법이 있을까요?
dt = Current Data Table();
cnmes = dt << get column names( "string" );
For( j = 1, j <= N Items( cnmes ), j++,
if (Starts With( cnmes[j], "1" ) == 1 | Starts With( cnmes[j], "2" ) == 1 | Starts With( cnmes[j], "3" ) == 1| Starts With( cnmes[j], "4" ) == 1 | Starts With( cnmes[j], "5" ) == 1 | Starts With( cnmes[j], "6" ) == 1 | Starts With( cnmes[j], "7" ) == 1 | Starts With( cnmes[j], "8" ) ==1 | Starts With( cnmes[j], "9" ) == 1 | Starts With( cnmes[j], "0") == 1 ,
Column(cnmes[j]) << set name("_"||cnmes[j])
) );
자동화 및 스크립팅Re: 숫자 이니셜이 있는 열 이름Column() 함수를 사용하여 "cnmes" 열 이름 목록에서 열 이름을 참조할 수 있습니다. 또는 열 이름을 하드코딩하는 경우 다음을 사용하세요.
// Report snapshot: Big Class - Graph Builder
Data Table( "Big Class" ) << Graph Builder(
Variables( X( :"1height"n ), Y( :"1height"n ) ),
Elements( Points( X, Y, Legend( 6 ) ), Smoother( X, Y, Legend( 7 ) ) )
);

names default to here(1);
dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
// Change column name: height → 1height
try(Data Table( "Big Class" ):height << Set Name( "1height" ));
// Change column name: weight → 3weight
try(Data Table( "Big Class" ):weight << Set Name( "3weight" ));
cnmes = dt << get column names( "string" );
Graph Builder(
Variables( X( column(cnmes[5])), Y( column(cnmes[4]) ) ),
Elements( Points( X, Y, Legend( 6 ) ), Smoother( X, Y, Legend( 7 ) ) )
);
Re: 숫자 이니셜이 있는 열 이름이름은 알파벳 문자 또는 밑줄로 시작해야 하기 때문에 이러한 문제가 발생합니다 (스크립팅 가이드 > JSL 구성 요소 > JSL 구문 규칙 > 이름) . 작업 내용에 따라 이름을 바꿀지 말지 결정할 수 있습니다(txnelson의 옵션 참조). 이름을 바꾸려면 다음과 같이 정규식을 사용할 수 있습니다.
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(0),
Compress File When Saved(1),
New Column("1col", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("13col", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("0col", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("Column 4",
Numeric,
"Continuous",
Format("Best", 12),
Set Values([])
)
);
colnames = dt << Get Column Names("String");
For Each({colname}, colnames,
newname = Regex(colname, "^\d+.+", "_\0");
If(!IsMissing(newname),
Column(dt, colname) << Set Name(newname);
);
);