3 Adding Attributes
Richard Townsend edited this page 2014-08-10 05:50:13 -07:00
// Create a new, empty DenseInstances
newInst := base.NewDenseInstances()

// Create some Attributes 
attrs := make([]base.Attribute, 2)
attrs[0] = base.NewFloatAttribute("Arbitrary Float Quantity")
attrs[1] = new(base.CategoricalAttribute)
attrs[1].SetName("Class")

// Add the attributes
newSpecs := make([]base.AttributeSpec, len(attrs))
for i, a := range attrs {
    newSpecs[i] = newInst.AddAttribute(a)
}

Code excerpt: Adding two new Attributes to a blank UpdatableDataGrid

  • Attributes can only be added to empty UpdatableDataGrids (i.e. before calling Extend to allocate memory).
  • AddAttribute returns an [AttributeSpec](Attribute Specifications) describing where the Attribute was inserted.