数据框快速到datatable r.net

时间:2017-08-06 23:39:15

标签: c# datatable r.net

我想知道是否有更好的方法将数据网从rnet转换为system.data或类似的数据表。 目前,我正在做的是

Dataframe dataset = engine.evaluate ("some dataframe"). AsDataframe ();
DataTable dtable = new DataTable ();

  For (int i = 0; i <dataset.ColumnCount; ++ i)
             {
                 Dtable.Columns.Add (dataset.ColumnNames [i]);
             }

             For (int k = 0; k <dataset.RowCount; ++ k)
             {
                 Dtable.Rows.Add (dataset.GetRow (k) .DataFrame);

             }

             For (int i = 0; i <dataset.RowCount; i ++)
             {
                 For (int j = 0; j <dataset.ColumnCount; j ++)
                 {
                     Dtable.Rows [i] [j] = dataset [i, j];
                 }
             }

然而,该方法非常慢,并且想知道是否有更快的方法。

问候

1 个答案:

答案 0 :(得分:0)

您可以轻松消除一个for循环

Dataframe dataset = engine.evaluate ("some dataframe"). AsDataframe ();
DataTable dtable = new DataTable ();

For (int i = 0; i <dataset.ColumnCount; ++ i)
{
   Dtable.Columns.Add (dataset.ColumnNames [i]);
}


For (int i = 0; i <dataset.RowCount; i ++)
{
   DataRow newRow = Dtable.Rows.Add();
   For (int j = 0; j <dataset.ColumnCount; j ++)
   {
      newRow[j] = dataset [i, j];
   }
}