Index: /trunk/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
===================================================================
--- /trunk/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs	(revision 16062)
+++ /trunk/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs	(revision 16063)
@@ -116,17 +116,5 @@
 
     public ModifiableDataset ToModifiable() {
-      var values = new List<IList>();
-      foreach (var v in variableNames) {
-        if (VariableHasType<double>(v)) {
-          values.Add(new List<double>((IList<double>)variableValues[v]));
-        } else if (VariableHasType<string>(v)) {
-          values.Add(new List<string>((IList<string>)variableValues[v]));
-        } else if (VariableHasType<DateTime>(v)) {
-          values.Add(new List<DateTime>((IList<DateTime>)variableValues[v]));
-        } else {
-          throw new ArgumentException("Unknown variable type.");
-        }
-      }
-      return new ModifiableDataset(variableNames, values);
+      return new ModifiableDataset(variableNames, variableNames.Select(v => variableValues[v]),true);
     }
 
@@ -141,5 +129,5 @@
     }
 
-    protected Dataset(Dataset dataset) : this(dataset.variableNames, dataset.variableValues.Values) { }
+
 
     #region Backwards compatible code, remove with 3.5
@@ -318,7 +306,8 @@
     #region IStringConvertibleMatrix Members
     [Storable]
-    protected int rows;
+    private int rows;
     public int Rows {
       get { return rows; }
+      protected set { rows = value; }
     }
     int IStringConvertibleMatrix.Rows {
Index: /trunk/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs
===================================================================
--- /trunk/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs	(revision 16062)
+++ /trunk/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs	(revision 16063)
@@ -47,7 +47,10 @@
     public ModifiableDataset() { }
 
-    public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues) :
-      base(variableNames, variableValues, cloneValues: false) { }
-
+    public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues, bool cloneValues = false) :
+      base(variableNames, variableValues, cloneValues) { }
+
+    public Dataset ToDataset() {
+      return new Dataset(variableNames, variableNames.Select(v => variableValues[v]));
+    }
     public void ReplaceRow(int row, IEnumerable<object> values) {
       var list = values.ToList();
@@ -91,5 +94,5 @@
         variableValues[variableNames[i]].Add(list[i]);
       }
-      rows++;
+      Rows++;
       OnRowsChanged();
       OnReset();
@@ -104,4 +107,7 @@
         throw new ArgumentException("Cannot add variable with no values.");
 
+      if (values.Count != Rows)
+        throw new ArgumentException(string.Format("{0} values are provided, but {1} rows are present in the dataset.", values.Count, Rows));
+
       if (!IsAllowedType(values))
         throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName));
@@ -109,4 +115,29 @@
       variableValues[variableName] = values;
       variableNames.Add(variableName);
+
+      OnColumnsChanged();
+      OnColumnNamesChanged();
+      OnReset();
+    }
+
+
+    public void InsertVariable(string variableName, int position, IList values) {
+      if (variableValues.ContainsKey(variableName))
+        throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName));
+
+      if (position < 0 || position > Columns)
+        throw new ArgumentException(string.Format("Incorrect position {0} specified. The position must be between 0 and {1}.", position, Columns));
+
+      if (values == null || values.Count == 0)
+        throw new ArgumentException("Cannot add variable with no values.");
+
+      if (values.Count != Rows)
+        throw new ArgumentException(string.Format("{0} values are provided, but {1} rows are present in the dataset.", values.Count, Rows));
+
+      if (!IsAllowedType(values))
+        throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName));
+
+      variableNames.Insert(position, variableName);
+      variableValues[variableName] = values;
 
       OnColumnsChanged();
@@ -129,5 +160,5 @@
       foreach (var list in variableValues.Values)
         list.RemoveAt(row);
-      rows--;
+      Rows--;
       OnRowsChanged();
       OnReset();
