The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

SPVM::R::OP::DataFrame - Data Frame Operations

Description

R::OP::DataFrame class in SPVM has methods for operations for 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;
  
  my $data_frame1 = R::DataFrame->new;
  
  $data_frame1->set_col("name", STROP->c(["Ken", "Yuki", "Mike"]));
  $data_frame1->set_col("age", IOP->c([19, 43, 50]));
  $data_frame1->set_col("weight", DOP->c([(double)50.6, 60.3, 80.5]));
  
  my $data_frame2 = R::DataFrame->new;
  
  $data_frame1->set_col("name", STROP->c(["Jonh"]));
  $data_frame1->set_col("age", IOP->c([25]));
  $data_frame1->set_col("weight", DOP->c([(double)40.6]));
  
  my $data_frame3 = DFOP->cbind($data_frame1, $data_frame2);

See also Data Frame Examples.

Class Methods

cbind

static method cbind : R::DataFrame ($x_data_frame : R::DataFrame, $y_data_frame : R::DataFrame);

Creates a new R::DataFrame object, adds all columns of $x_data_frame and all columns of $y_data_frame are added to the new data frame object, and returns the new data frame object.

This method calls R::DataFrame#insert_col method.

Exceptions:

The data frame $x_data_frame must be defined. Otherwise, an exception is thrown.

The data frame $y_data_frame must be defined. Otherwise, an exception is thrown.

Exceptions thrown by R::DataFrame#insert_col method could be thrown.

rbind

static method rbind : R::DataFrame ($x_data_frame : R::DataFrame, $y_data_frame : R::DataFrame);

Creates a new R::DataFrame object, adds all rows of $x_data_frame and all rows of $y_data_frame are added to the new data frame object, and returns the new data frame object.

Exceptions:

The data frame $x_data_frame must be defined. Otherwise, an exception is thrown.

The data frame $y_data_frame must be defined. Otherwise, an exception is thrown.

The column numbers of the data frame $x_data_frame must be equal to the column numbers of the data frame $y_data_frame.

The column name at column index $i of the data frame $x_data_frame must be equal to the column name at column index $i of the data frame $y_data_frame. Otherwise, an exception is thrown.

The type of the n-dimensional array at column index $i of the data frame $x_data_frame must be equal to the type of the n-dimensional array at column index $i of the data frame $y_data_frame. Otherwise, an exception is thrown.

($i is a column index)

subset

static method subset : R::DataFrame ($x_data_frame : R::DataFrame, $indexes : R::NDArray::Int, $options : object[] = undef);

Gets the subset of the data frame $x_data_frame given the indexes $indexes and the options $options, and returns the subset.

Same as the following code using R::DataFrame#slice method.

  $x_data_frame->slice($colnames, [$indexes]);

($colnames is the value of key select in the options $options.)

Options:

  • select : string[] = undef

    Column names.

Exceptions:

The data frame $x_data_frame must be defined. Otherwise, an exception is thrown.

The first column of $x_data_frame must be a vector if columns exists. Otherwise, an exception is thrown.

Exceptions thrown by R::DataFrame#slice method could be thrown.

na_omit

static method na_omit : R::DataFrame ($x_data_frame : R::DataFrame);

Gets the subset of the $x_data_frame which rows does not contains NA data and returns the subset.

This method calls "subset" method.

Exceptions:

The data frame $x_data_frame must be defined.

Exceptions thrown by "subset" method could be thrown.

See Also

Copyright & License

Copyright (c) 2024 Yuki Kimoto

MIT License