Class: R::DataFrame

Inherits:
Object show all
Includes:
IndexedObject, MDIndexedObject
Defined in:
lib/R_interface/rdata_frame.rb

Instance Attribute Summary

Attributes inherited from Object

#r_interop, #statement

Instance Method Summary collapse

Methods included from MDIndexedObject

#[]

Methods included from IndexedObject

#[], #size

Methods inherited from Object

#==, #_, #attr=, build, #comment, #comment=, #dim, #dim=, #dimnames, #dimnames=, #eql, #initialize, #method_missing, #names, #names=, #pp, #pretty_print, #rclass, #rclass=, #row__names, #row__names=, #setR, #setR_name, #to_s, #tsp, #tsp=

Constructor Details

This class inherits a constructor from R::Object

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class R::Object

Instance Method Details

#[]=(index, *args) ⇒ Object


subset assign a vector with an index to a value index can span multiple values, for ex., R.c(2, 3, 5)


Parameters:

  • index (Array)

    The vector index

  • values (R::Object)

    The values to assign to the index. Note that



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/R_interface/rdata_frame.rb', line 54

def []=(index, *args)
  values = args[-1]
  idx2 = (args.size > 1)? args[-2] : false
  
  # dealing with double indexing function '[['
  if (index.is_a? Array)
    setR_name("`[[<-`", R.empty_symbol, *index, values)
  else
    idx2 ? setR_name("`[<-`", index, idx2, values) :
      setR_name("`[<-`", R.empty_symbol, index, values)
  end
  
  self
  
end

#each_columnObject


Goes through each column of the dataframe and return the whole column as the first element and the column name (Ruby string) as the second




90
91
92
93
94
95
96
97
98
# File 'lib/R_interface/rdata_frame.rb', line 90

def each_column
  
  # ncol is the R function that return the number of columns in the dataset.  This
  # function returns a R::Vector, so we need to extract its first element (<< 0)
  (1..ncol >> 0).each do |i|
    yield self[:all, i], self.names[i] >> 0
  end
  
end

#each_rowObject


Goes through each row of the dataframe and return the whole row as the first element and the row name (Ruby string) as the second




75
76
77
78
79
80
81
82
83
# File 'lib/R_interface/rdata_frame.rb', line 75

def each_row

  # nrow is the R function that return the number of rows in the dataset.  This
  # function returns a R::Vector, so we need to extract its first element (<< 0)
  (1..nrow >> 0).each do |i|
    yield self[i, :all], self.rownames[i] >> 0
  end

end

#method_missing_assign(column_name, arg) ⇒ Object





42
43
44
# File 'lib/R_interface/rdata_frame.rb', line 42

def method_missing_assign(column_name, arg)
  setR_name("`[<-`", R.empty_symbol, column_name, arg)
end

#qplot(*args) ⇒ Object


Calls the R.qplot adding the data: parameter




34
35
36
# File 'lib/R_interface/rdata_frame.rb', line 34

def qplot(*args)
  print R.qplot(*args, data: self)
end