如何插入多条没有列名的数据?下面是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);