是的,可變數量的蔬菜會使這更複雜。 在腳本而不是公式中構建連接值可能更容易。
看看這個版本的腳本,看看我會怎麼做。
orig = New Table( "Fruit vs Veggies",
Add Rows( 48 ),
New Column( "Fruit",
Character,
"Nominal",
Set Values(
{"Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb",
"Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb",
"Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Chrnb2", "Chrnb2", "Chrnb2",
"Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2",
"Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2",
"Chrnb2", "Chrnb2"}
)
),
New Column( "Vegetable",
Character,
"Nominal",
Set Values(
{"nuclear chromosome", "cellular_component", "intracellular", "cell", "nucleus",
"chromosome", "organelle", "immune system process", "biological_process",
"anatomical structure development", "DNA metabolic process",
"cellular nitrogen compound metabolic process", "molecular_function", "cytoplasm",
"cytoskeleton", "DNA binding", "nucleotidyltransferase activity",
"biosynthetic process", "response to stress", "cell death", "signal transduction",
"cytoskeletal protein binding", "lyase activity", "enzyme binding",
"homeostatic process", "ion binding", "protein complex",
"cellular component assembly", "cellular nitrogen compound metabolic process",
"transmembrane transport", "ion binding", "cell proliferation",
"immune system process", "nervous system process", "response to stress",
"cell-cell signaling", "molecular_function", "cell", "cell morphogenesis",
"biological_process", "anatomical structure development", "cell differentiation",
"transport", "signal transduction", "plasma membrane", "cellular_component",
"signal transducer activity", "transmembrane transporter activity"}
)
),
New Column( "Vegetable number",
Numeric,
"Nominal",
Format( "Best", 9 ),
Formula( Col Rank( :Vegetable, :Fruit ) )
)
);
split = orig << Split(
Split By( :Vegetable number ),
Split( :Vegetable ),
Group( :Fruit ),
Sort by Column Property
);
vc = {};
For( i = 1, i <= N Row( split ), i++,
vc[i] = Column( 2 )[i];
For( j = 3, j <= N Col( split ), j++,
If( Column( j )[i] != "",
vc[i] = vc[i] || ", " || Column( j )[i]
)
);
);
split << New Column( "Veggies_concat", character, set values( vc ) );嗨,傑夫,
非常感謝您的快速回复。你對問題的描述就此打住。
但是,蔬菜類型的數量可能會因每種水果而異,這將導致填充的列數不同。 這導致在末尾有額外的逗號/分隔符(可以清理)。 此外,一旦編寫了腳本,它就不允許在每次執行腳本時自動調整不同數量的不同項目(即蔬菜)。
任何關於能夠在拆分步驟後自動調整列數的建議將不勝感激。
多謝
塞巴斯蒂安
New Table( "Fruit vs Veggies",
Add Rows( 48 ),
New Script(
"Source",
Data Table( "mart_export (1)" ) << Subset(
Selected Rows( 0 ),
Rows(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48]
),
columns( :Fruit, :Vegetable )
)
),
New Script(
"Concatenate vegetables per fruits",
dt = Data Table( "Fruit vs Veggies" );
New Column( "Vegetable number",
Character,
"Nominal",
formula( Col Rank( :Vegetable, :Fruit ) )
);
Data Table( "Fruit vs Veggies" ) << Split(
Split By( :Vegetable number ),
Split( :Vegetable ),
Group( :Fruit ),
Output Table( "Strange fruits" ),
Sort by Column Property
);
Data Table( "Strange fruits" ) << New Column( "Vegggies_concat",
Character,
"Nominal",
formula(
:Name( "1" ) || ", " || :Name( "2" ) || ", " || :Name( "3" ) || ", " ||
:Name( "4" ) || ", " || :Name( "5" ) || ", " || :Name( "6" ) || ", " ||
:Name( "7" ) || ", " || :Name( "8" ) || ", " || :Name( "9" ) || ", " ||
:Name( "10" ) || ", " || :Name( "11" ) || ", " || :Name( "12" ) || ", "
|| :Name( "13" ) || ", " || :Name( "14" ) || ", " || :Name( "15" ) ||
", " || :Name( "16" ) || ", " || :Name( "17" ) || ", " || :Name( "18" )
|| ", " || :Name( "19" ) || ", " || :Name( "20" ) || ", " ||
:Name( "21" ) || ", " || :Name( "22" ) || ", " || :Name( "23" ) || ", "
|| :Name( "24" ) || ", " || :Name( "25" ) || ", " || :Name( "26" ) ||
", " || :Name( "27" )
)
);
Data Table( "Strange fruits" ) << Subset(
Output Table( "Strange fruits_clean" ),
All rows,
columns( :Fruit, :Vegggies_concat )
) << close window;
),
New Column( "Fruit",
Character,
"Nominal",
Set Values(
{"Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb",
"Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb",
"Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb", "Polb",
"Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2",
"Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2",
"Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2", "Chrnb2"}
)
),
New Column( "Vegetable",
Character,
"Nominal",
Set Values(
{"nuclear chromosome", "cellular_component", "intracellular", "cell",
"nucleus", "chromosome", "organelle", "immune system process",
"biological_process", "anatomical structure development",
"DNA metabolic process", "cellular nitrogen compound metabolic process",
"molecular_function", "cytoplasm", "cytoskeleton", "DNA binding",
"nucleotidyltransferase activity", "biosynthetic process",
"response to stress", "cell death", "signal transduction",
"cytoskeletal protein binding", "lyase activity", "enzyme binding",
"homeostatic process", "ion binding", "protein complex",
"cellular component assembly",
"cellular nitrogen compound metabolic process", "transmembrane transport",
"ion binding", "cell proliferation", "immune system process",
"nervous system process", "response to stress", "cell-cell signaling",
"molecular_function", "cell", "cell morphogenesis", "biological_process",
"anatomical structure development", "cell differentiation", "transport",
"signal transduction", "plasma membrane", "cellular_component",
"signal transducer activity", "transmembrane transporter activity"}
)
),
New Column( "Vegetable number",
Numeric,
"Nominal",
Format( "Best", 9 ),
Formula( Col Rank( :Vegetable, :Fruit ) )
)
)