如何插入多條沒有列名的數據?下面是JSL製作JMP表。
dt = 新表(“樓層示例”,
新列(“單位ID”,字符,名義),
新列(“數據1”,數字,連續,格式(“最佳”,12)),
新列(“Data2”,數字,連續,格式(“最佳”,12)),
新列(“Data3”,數字,連續,格式(“最佳”,12)),
);
dt數據={
{單位 ID =“A”,數據 1 = 1.1,數據 2 = 2.1,數據 3 = 3.1},
{單位 ID =“B”,數據 1 = 1.2,數據 2 = 2.2,數據 3 = 3.2},
{單位 ID =“C”,數據 1 = 1.3,數據 2 = 2.3,數據 3 = 3.3}
};
dt << 添加行( dtdata );
我想插入多個數據而不定義列名,如下所示。
dt數據={
{“A”, 1.1, 2.1, 3.1},
{“B”, 1.2, 2.2, 3.2},
{“C”,1.3,2.3,3.3}
};
以上不是正確答案。 請讓我知道正確的 JSL 語法。
回复: 如何插入多條沒有列名的數據?文檔中介紹了這種情況。 請參閱幫助 > 書籍 > 腳本指南。 有一節介紹了向數據表添加行的不同方法。 整個指南中有很多示例。 以下是摘錄:
添加行
要添加行,請發送“添加行”消息並指定行數。 您還可以指定在哪一行之後插入新行。 參數可以是數字或表達式評估為數字。
dt << Add Rows( 3 ); // add 3 rows to bottom of data table
dt << Add Rows( 3, 10 ); /* add 3 rows after the 10th row, moving the 11th and lower rows farther down */
添加行的變體允許您指定一個參數,生成一個分配列表。
賦值可以用逗號或分號分隔。
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Add Rows(
{:name = "Peter", :age = 14, :sex = "M", :height = 61, :weight = 124}
);
或者
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Add Rows(
{:name = "Peter"; :age = 14; :sex = "M"; :height = 61; :weight = 124}
);
您可以發送多個參數來生成列表,甚至是列表的列表。 以下腳本
使用各種添加行命令創建一個數據表:
dt = New Table( "Cities" );
dt << New Column( "xx", Numeric );
dt << New Column( "cc", Character, width( 12 ) );
dt << Add Rows( {xx = 12, cc = "Chicago"} ); // single list
dt << Add Rows( {xx = 13, cc = "New York"}, {xx = 14, cc = "Newark"} );
// several lists
dt << Add Rows(
{{xx = 15, cc = "San Francisco"}, {xx = Sqrt( 256 ), cc = "Oakland"}}
); // list of lists
a = {xx = 20, cc = "Miami"};
dt << Add Rows( a ); // evaluate as single list
b={{xx = 17, cc = "San Antonio"},{xx = 18, cc = "Houston"}, {xx = 19, cc =
"Dallas"}};
dt << Add Rows( b ); // evaluate as list of lists
回复: 如何插入多條沒有列名的數據?以下是一些適用於 JMP 13 及更高版本的選項。
dt = New Table( "Floor Example",
New Column( "Unit ID", Character, Nominal ),
New Column( "Data1", Numeric, Continuous, Format( "Best", 12 ) ),
New Column( "Data2", Numeric, Continuous, Format( "Best", 12 ) ),
New Column( "Data3", Numeric, Continuous, Format( "Best", 12 ) ),
);
dt << add rows(nitems(dtdata));
dtdata={
{"A", 1.1, 2.1, 3.1},
{"B", 1.2, 2.2, 3.2},
{"C", 1.3, 2.3, 3.3}
};
For Each Row(dt, dt[row(),1::ncol(dt)]=dtdata[row()]);
//or create a function to append
addrows = function({listofrows, ctbl=current data table()}, {nr,nc, i},
nr = nrow(ctbl);
nc = ncol(ctbl);
for(i=1, i <= nitems(listofrows), i++,
ctbl << add rows(1);
ctbl[nr+i, 1::nc] = listofrows[i]
);
); //end function
//add the rows again to demo this function
addrows(dtdata);