programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• paul wheaton
• Devaka Cooray
Sheriffs:
• Jeanne Boyarsky
• Tim Cooke
• Liutauras Vilda
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Carey Brown
• Piet Souris
Bartenders:
• salvin francis
• Mikalai Zaikin
• Himai Minh

# How to convert from double to double[][] and add multiple columns to dataframe?

Ranch Hand
Posts: 102
2
• Number of slices to send:
Optional 'thank-you' note:
I'm trying to use this method from the Smile library:

but I'd like to add one double integer as the value in the Dataframe,

so I'm wondering how I can convert a double to double[][] or if there is a better way to add the value to the dataframe?

Additionally I'd like to add multiple columns with one double integer, for ex. I'd have 5 columns with 1 row:

so I'm wondering if I have to make 5 separate dataframes and then merge them all together or if I can do that in less steps?

Thanks so much!

Saloon Keeper
Posts: 4383
163
• 1
• Number of slices to send:
Optional 'thank-you' note:
hi Glenda,

this works:

or this:

and y is a 1x1 double[][].

If you have one row (as in your example, header not included), then you can turn that into a double[][] as well, like in:

You get a 5 x 1 double[][], assuming that a row in your 2D array is a column in your daraframe. Then uae the constructor.

Glenda Karen
Ranch Hand
Posts: 102
2
• Number of slices to send:
Optional 'thank-you' note:
Thanks so much!

I converted the double to double[][]

Is there any way to make the dataframe with header names as well? Something like:

Glenda Karen
Ranch Hand
Posts: 102
2
• Number of slices to send:
Optional 'thank-you' note:
What I did so far is make multiple dataframes and then combine them in one merge:

This works but makes a lot of extra dataframes.

Piet Souris
Saloon Keeper
Posts: 4383
163
• 1
• Number of slices to send:
Optional 'thank-you' note:

Glenda Karen wrote:Is there any way to make the dataframe with header names as well? Something like:

If you use a double[][] (or int[][]) in your constructor, then that 2D array contains all of the data already. So you only need one gouble[][], and in the constructor you used in your opening post, you then specified all the column names. Isn't that exactly what you wish?

If you cannot use a double[][] in your constructor (for instance when some of the columns are not doubles), then using the constructor with BaseVectors (see thr API and a previous topic) also seems very handy.

And last but least: so you are creating a few extra dataframes. If that does not take hours, or many GigaBytes of memory: so what?

Glenda Karen
Ranch Hand
Posts: 102
2
• Number of slices to send:
Optional 'thank-you' note:
Thanks so much! That's great!
And yes true point, not such a big deal to make a few dataframes, I actually ended up going with that and worked well!