열 머리글 검색 및 바꾸기안녕,
다음을 사용하여 열 머리글 이름을 정확한 이름으로 바꿀 수 있습니다. :높이 << 이름 설정( "테스트" );
텍스트 목록이 있으면 ""로 바꾸고 싶습니다.
어떻게 진행해야 합니까?
"이름" "시간" "성별" "키 abc 체중" "체중 xyz" "12 키 테스트"
케이티 12 여성 59 95 59
루이스 12 여성 61 123 61
최종 출력:
"이름" "시간" "성별" "abc" "xyz" "12 테스트"
Names Default To Here( 1 );
dt = Open( "C:/JSL/BigClass.jmp" );
headerList = dt << get column names( string );
//:height << Set Name( "test" );
For( i = 1, i <= N Items( headerList ), i++,
If( (headerList[i] == "height" || headerList[i] == "weight"), //trying to find any column header has height or weight and replace with ""
Column( dt, colList[i] ) << set name( " " ) //above are just two examples, maybe put it in list and loop?
)
);
스크립팅Re: 열 헤더 검색 및 바꾸기안녕 샘,
여전히 대체하고 있는 두 번째 루프(j)에서 열의 이름을 직접 바꾸는 것이 문제인 것 같습니다.
한 가지 가능한 솔루션(아래 표시)은 헤더 목록(hl)을 수정한 다음 모든 변경이 이루어진 후 열 이름을 바꾸는 것입니다.
Names Default To Here( 1 );
dt = Open( "C:\Program Files\SAS\JMP\14\Samples\Data\Big Class.jmp" );
hl = dt << get column names( string );
sr = List();
sr[1] = "height"; //
sr[2] = "e"; // Order of replacement strings is critical
sr[3] = "a"; //
For( i = 1, i <= N Items( hl ), i++,
For (j = 1, j <= N Items (sr), j++,
If (contains (hl [i], sr [j]),
txt = substitute (hl [i], sr [j], "x"); // Just for clarity: the expression could be wrapped into the next
Substitute into (hl, hl [i], txt); // Hold all the changes into the hl list
)
);
Column (dt , i ) << set name (hl [i]); // Renames column only after all changes have been made
);
도움이 되길 바랍니다.
최상의,
TS
Re: 열 헤더 검색 및 바꾸기미리 목록을 정의하고 이중 중첩 루프를 시도했습니다. 만 대체 문자열 바꾸기[3].
headerList = dt << get column names( string );
stringReplace = List();
stringReplace[1] = "height";
stringReplace[2] = "e";
stringReplace[3] = "a";
For( i = 1, i <= N Items( headerList ), i++,
For( j = 1, j <= N Items( stringReplace ), j++,
Column( dt, i ) << set name( Substitute(headerList[i], stringReplace[j], "" ) )
);
);
Re: 열 헤더 검색 및 바꾸기안녕 샘,
귀하의 스크립트에서 두 가지 문제를 발견했습니다.
- 연결 "||"을 사용했습니다. "Or" 문을 나타내는 코드("|"이어야 함)
- JMP에서는 열 이름을 " "로 지정할 수 없습니다.
또한 일반적으로 열 이름 목록을 반복하는 대신 번호로 열을 호출하는 것이 더 빠르고 쉽습니다.
그래서 제가 생각해낸 것이 있습니다.
Names Default To Here( 1 );
dt = Open( "C:\Program Files\SAS\JMP\14\Samples\Data\Big Class.jmp" );
headerList = dt << get column names( string );
For( i = 1, i <= N Items( headerList ), i++,
If( (headerList[i] == "height" | headerList[i] == "weight"), //Fixed the "Or" statement
Column( dt, i ) << set name(substitute (headerList [i], "e", "x")) //Used the substitute function as an example, you can replace any string with ""?
)
);