据帧到数据表r.net快速度(Dataframe to datatable r.net fastly

2019-11-04 09:52发布

我想知道是否有更好的方法将datanet从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];
                 }
             }

然而,这种方法很慢,想知道是否有其他方法更快。

问候

Answer 1:

您可以轻松消灭一个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];
   }
}


文章来源: Dataframe to datatable r.net fastly