here和here之前已经问过这个问题,但我的问题没有得到有用的答案。我的数据集中没有遗漏数据,并尝试从model.matrix
创建model.frame
。这是一个可重复的例子:
dat = data.frame(x = rep(1:3, each = 5),
y = rnorm(15),
z = rep(c(1,1.1,1.3), each = 5))
# this works
mt = model.matrix(model.frame(lm(y ~ x,dat)))
# this produces the error
mt = model.matrix(model.frame(lm(y ~ x + z,dat)))
为什么以及如何解决这个问题?或者,如何以另一种有效且稳健的方式使用截距列获得右侧值的矩阵?
答案 0 :(得分:1)
问题是private void sendData(int total, DataGridView dgv, Image v)
{
Thread t = new Thread(() => ResponseThread(total, dgv,v));
t.Start();
}
private void ResponseThread(int t, DataGridView dgv, Image u)
{
String table="";
HttpListenerContext context = _httpListener.GetContext();
for (int i = 0; i < t; i++)
table += "<tr><td>" + dgv.Rows[i].Cells[0].Value.ToString() + "</td><td>" + dgv.Rows[i].Cells[1].Value.ToString() + "</td><td>" +
dgv.Rows[i].Cells[2].Value.ToString() + "</td><td>" + dgv.Rows[i].Cells[3].Value.ToString() + "</td><td>" + dgv.Rows[i].Cells[4].Value.ToString() +
"</td><td>" + dgv.Rows[i].Cells[5].Value.ToString() + "</td></tr>";
byte[] _responseArray = Encoding.UTF8.GetBytes(
"<html>" +
"<head>" +
"<title>Hello</title>" +
"</head>" +
"<body>" +
"<h1>Total: " + t +
"<table style=\"width:100%\"> <tr><b><th>No</th><th>Centroid X</th><th>Centroid Y</th><th>Orientation</th><th>Area</th><th>Area (mm)</th></b></tr>"+
table+"</table>"+
"<img src="+u+"></img>"+
"<p><i>Last Update: " + DateTime.Now.ToShortDateString() + " "+DateTime.Now.ToLongTimeString()+
"</i></p>" +
"</h1></body></html>");
context.Response.OutputStream.Write(_responseArray, 0, _responseArray.Length);
context.Response.KeepAlive = true;
context.Response.Close();
}
期望公式或术语对象作为第一个参数。解决方案:
model.matrix()