Java Object Analogue to R Data.Frame

Java object analogue to R data.frame

I have just open-sourced a first draft version of Paleo, a Java 8 library which offers data frames based on typed columns (including support for primitive values). Columns can be created programmatically (through a simple builder API), or imported from text file.

Please refer to the README for further details.

The project is still wet from birth – I am very interested in feedback / PRs, tia!

Java: datastructure for a table with typeparameter for row, column and value

As far as i know there was no built in Tables. But even in this design, what will you be able to achieve without the standard queries? You might want to rethink your design if your approach is just to have tables, visualization and what coded may be different.

But alternatively you may try:

  1. Build a multi dimensional array (limited with same data type).
  2. The standard of list of objects/classes. i.e. list.add(new Data(col1, col2));
  3. Look into Guava's Library on Table.
  4. Checkout other libraries, in particular for the keyword DataFrame. It's a key for many analytical tools.

Java: datastructure for a table with typeparameter for row, column and value

As far as i know there was no built in Tables. But even in this design, what will you be able to achieve without the standard queries? You might want to rethink your design if your approach is just to have tables, visualization and what coded may be different.

But alternatively you may try:

  1. Build a multi dimensional array (limited with same data type).
  2. The standard of list of objects/classes. i.e. list.add(new Data(col1, col2));
  3. Look into Guava's Library on Table.
  4. Checkout other libraries, in particular for the keyword DataFrame. It's a key for many analytical tools.

In R, different behavior between `is.list(x)` and `is(x,'list')`

You are mixing S3 and S4 class conventions. is and extends are for S4 classes but these work with S3 ones because of the way these have been implemented. inherits was written for S3 classes and it is not intended to work with S4 objects with full compatibility.

inherits effectively compares the result of class(x) with the class you specify in the second argument. Hence

> class(data.frame())
[1] "data.frame"

doesn't contain "list" anywhere so fails.

Note also this from ?inherits:

 The analogue of ‘inherits’ for formal classes is ‘is’.  The two
functions behave consistently with one exception: S4 classes can
have conditional inheritance, with an explicit test. In this
case, ‘is’ will test the condition, but ‘inherits’ ignores all
conditional superclasses.

Another confusion is with the class of an object and the implementation of that object. Yes a data frame is a list as is.list() tells us, but in R's S3 class world, data.frame() is of class "data.frame" not "list".

As for is(data.frame(),'list'), well it isn't of that specific class "list" hence the FALSE. What is(data.frame()) does is documented in ?is

Summary of Functions:

‘is’: With two arguments, tests whether ‘object’ can be treated as
from ‘class2’.

With one argument, returns all the super-classes of this
object's class

Hence is(data.frame()) is showing the classes that the "data.frame" class extends (in the S4 sense, not the S3 sense). This further explains the extends('data.frame','list') behaviour as in the S4 world, the "data.frame" class does extend the "list" class.

Java-R integration?

I have successfully used two alternatives in the past.

JRI

  • Pros: probably better performance.
  • Cons: you have to configure some environment variables and libraries, different in Win/UNIX.

RServe

  • Pros: easy to setup, you don't need to initialize R or link against
    any R library, can run in a different machine.
  • Cons: based on TCP/IP (a server is running), no callbacks from R.

Other alternatives I have never used : RCaller

Convert Named Character Vector to data.frame

It's as simple as data.frame(as.list(testVect)). Or if you want sensible data types for your columns, data.frame(lapply(testVect, type.convert), stringsAsFactors=FALSE).



Related Topics



Leave a reply



Submit