Name

SPVM::R::DataFrame - Short Description

Description

The R::DataFrame class in SPVM represents a data frame.

Usage

use R::DataFrame;
use R::OP::DataFrame as DFOP;
use R::OP::Int as IOP;
use R::OP::Double as DOP;
use R::OP::String as STROP;
use R::OP::Time::Piece as TPOP;

# Create a R::DataFrame object
my $data_frame = R::DataFrame->new;

$data_frame->set_col("name", STROP->c(["Ken", "Yuki", "Mike"]));
$data_frame->set_col("age", IOP->c([19, 43, 50]));
$data_frame->set_col("weight", DOP->c([(double)50.6, 60.3, 80.5]));
$data_frame->set_col("birth", TPOP->c(["1980-10-10", "1985-12-10", "1970-02-16"]));

my $data_frame_string = $data_frame->to_string;

my $slice_data_frame = $data_frame->slice(["name", "age"], [IOP->c([0, 1])]);

$data_frame->sort(["name", "age desc"]);

my $nrow = $data_frame->nrow;

my $ncol = $data_frame->ncol;

my $dim = $data_frame->first_col->dim;

Details

This class is a port of data frame features of R language.

Fields

colobjs_list;

has colobjs_list : List of R::DataFrame::Column;

colobjs_indexes_h

has colobjs_indexes_h : Hash of Int;

Class Methods

static method new : R::DataFrame ();

Instance Methods

colnames

method colnames : string[] ();

exists_col

method exists_col : int ($colname : string);

colname

method colname : string ($col : int);

colindex

method colindex : int ($colname : string);

col_by_index

method col_by_index : R::NDArray ($col : int);

first_col

method first_col : R::NDArray ();

col

method col : R::NDArray ($colname : string);

set_col

method set_col : void ($colname : string, $ndarray : R::NDArray);

insert_col

method insert_col : void ($colname : string, $ndarray : R::NDArray, $before_colname : string = undef);

ncol

method ncol : int ();

nrow

method nrow : int ();

remove_col

method remove_col : void ($colname : string);

clone

method clone : R::DataFrame ($shallow : int = 0);

to_string

method to_string : string ();

slice

method slice : R::DataFrame ($colnames : string[], $asix_indexes_product : R::NDArray::Int[]);

set_order

method set_order : void ($indexes_ndarray : R::NDArray::Int);

sort

method sort : void ($colnames_with_order_by : string[]);

order

method order : R::NDArray::Int ($colnames_with_order_by : string[]);

See Also

Copyright & License

Copyright (c) 2024 Yuki Kimoto

MIT License