protected function to_features($calculatedvalues) {

        // Null mean if all calculated values are null.
        $nullmean = true;
        foreach ($calculatedvalues as $value) {
            if (!is_null($value)) {
                // Early break, we don't want to spend a lot of time here.
                $nullmean = false;
                break;
            }
        }

        if ($nullmean) {
            $mean = null;
        } else {
            $mean = round(array_sum($calculatedvalues) / count($calculatedvalues), 2);
        }

        foreach ($calculatedvalues as $sampleid => $calculatedvalue) {

            if (!is_null($calculatedvalue)) {
                $calculatedvalue = round($calculatedvalue, 2);
            }

            if (static::include_averages()) {
                $calculatedvalues[$sampleid] = array($calculatedvalue, $mean);
            } else {
                // Basically just convert the scalar to an array of scalars with a single value.
                $calculatedvalues[$sampleid] = array($calculatedvalue);
            }
        }

        // Returns each sample as an array of values, appending the mean to the calculated value.
        return $calculatedvalues;
    }