1
$\begingroup$

Suppose that the information for constructing a dataset is split over two separate files: one file contains the numeric data, and a second file contains the names of the columns.

Is there a simple way to create a dataset from these two separate files?

$\endgroup$
1

2 Answers 2

6
$\begingroup$
columnames=CharacterRange["a","h"]; data= RandomInteger[9,{20,8}]; ds=Dataset[AssociationThread[columnames->#]&/@data] 

Mathematica graphics

$\endgroup$
2
$\begingroup$

OK, I found a second way. Like kglr's solution, this one also uses AssociationThread, but applies it only once:

makeDataset[columns_, columnLabels_] := Module[{labeledColumns, records}, labeledColumns = AssociationThread[columnLabels, columns]; records = Transpose[labeledColumns, AllowedHeads -> All]; Dataset[records] ]; 

The importer can be easily written in terms of makeDataset:

readDataset[datafile_, headerfile_] := Module[{columns, columnLabels}, columns = Transpose[Import[datafile]]; columnLabels = First[Import[headerfile]]; makeDataset[columns, columnLabels] ]; 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.