0

I'm using Rserve to call R functions using Java code. My project requires me to receive a vector and pass it to R. For example, I defined

ArrayList data = new ArrayList();
            data.add("10.0");
            data.add("11.0");
            data.add(null);

Then I got an array list: [10.0, 11.0, null]. I tried to use c.assign("x",data); to assign the array list to variable x, but Eclipse gave me an error

The method assign(String, String) in the type RConnection is not applicable for the arguments (String, ArrayList<String>)

So instead, I used

c.assign("x",data.toString());

to calculate

1.Fill rate (Return result should be 66.67%)

    nrow(matrix(x)) - sum(is.na(x)))/nrow(matrix(x))

2. Quantiles

    quantile (x, c(.01, .05, .1, .25, .5, .75, .9, .95, .99))

and got

 1.Fill rate = 1.0; 
 2.Error in calculating Quantiles because there is NULL value in the array list.

The results are obviously wrong. How do I assign an array list with NULL values to R vectors?

Basically I want R to recognize NULL or blank values passed from Java and do calculation. Really need help with this.

Many thanks!!!!!!!!!!!!!

1 Answer 1

1

If you are loading doubles you can use the REXPDouble class. This has has a constructor that will take a list of doubles. Use this to assign to the workspace. If you already have an array list just use the array list's built in function toArray() to convert it to an array.

    public REXPDouble(double[] load) {
            super();
            payload=(load==null)?new double[0]:load;
    }

conn.assign("whatever", rexpDoubles);

Alternatively there is also a REXPString.

/** create a new character vector
 *  @param load string elements of the vector */
public REXPString(String[] load) {
    super();
    payload=(load==null)?new String[0]:load;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.