예제 #1
0
  /** calculates the mean of the given numeric column */
  private void calcMean() {
    ArffSortedTableModel model;
    int i;
    double mean;

    // no column selected?
    if (m_CurrentCol == -1) return;

    model = (ArffSortedTableModel) m_TableArff.getModel();

    // not numeric?
    if (!model.getAttributeAt(m_CurrentCol).isNumeric()) return;

    mean = 0;
    for (i = 0; i < model.getRowCount(); i++)
      mean += model.getInstances().instance(i).value(m_CurrentCol - 1);
    mean = mean / model.getRowCount();

    // show result
    ComponentHelper.showMessageBox(
        getParent(),
        "Mean for attribute...",
        "Mean for attribute '"
            + m_TableArff.getPlainColumnName(m_CurrentCol)
            + "':\n\t"
            + Utils.doubleToString(mean, 3),
        JOptionPane.OK_CANCEL_OPTION,
        JOptionPane.PLAIN_MESSAGE);
  }
예제 #2
0
  /**
   * sets the specified values in a column to a new value
   *
   * @param o the menu item
   */
  private void setValues(Object o) {
    String msg;
    String title;
    String value;
    String valueNew;
    int i;
    ArffSortedTableModel model;

    value = "";
    valueNew = "";

    if (o == menuItemSetMissingValues) {
      title = "Replace missing values...";
      msg = "New value for MISSING values";
    } else if (o == menuItemSetAllValues) {
      title = "Set all values...";
      msg = "New value for ALL values";
    } else if (o == menuItemReplaceValues) {
      title = "Replace values...";
      msg = "Old value";
    } else return;

    value = ComponentHelper.showInputBox(m_TableArff.getParent(), title, msg, m_LastSearch);

    // cancelled?
    if (value == null) return;

    m_LastSearch = value;

    // replacement
    if (o == menuItemReplaceValues) {
      valueNew =
          ComponentHelper.showInputBox(m_TableArff.getParent(), title, "New value", m_LastReplace);
      if (valueNew == null) return;
      m_LastReplace = valueNew;
    }

    model = (ArffSortedTableModel) m_TableArff.getModel();
    model.setNotificationEnabled(false);

    // undo
    addUndoPoint();
    model.setUndoEnabled(false);
    String valueCopy = value;
    // set value
    for (i = 0; i < m_TableArff.getRowCount(); i++) {
      if (o == menuItemSetAllValues) {
        if (valueCopy.equals("NaN") || valueCopy.equals("?")) {
          value = null;
        }
        model.setValueAt(value, i, m_CurrentCol);
      } else if ((o == menuItemSetMissingValues) && model.isMissingAt(i, m_CurrentCol))
        model.setValueAt(value, i, m_CurrentCol);
      else if ((o == menuItemReplaceValues)
          && model.getValueAt(i, m_CurrentCol).toString().equals(value))
        model.setValueAt(valueNew, i, m_CurrentCol);
    }
    model.setUndoEnabled(true);
    model.setNotificationEnabled(true);
    model.notifyListener(
        new TableModelEvent(model, 0, model.getRowCount(), m_CurrentCol, TableModelEvent.UPDATE));

    // refresh
    m_TableArff.repaint();
  }