## Properties

empty
length

store
weighted

## Methods

clone()
deleteRecords(rs)
each(callback)
filter(callback)
filterByField(fieldName, minVal, maxVal)
filterByFq([minFq][, maxFq])
filterById([minId][, maxId])
getMatrix(fieldName)

getVector(fieldName)
join(joinName[, sampleSize])
map(callback)
reverse()
sample(num)
setDiff(rs)
setIntersect(rs)
setUnion(rs)

shuffle([seed])
sort(callback)
sortByField(fieldName[, asc])
sortByFq([asc])
sortById([asc])
split(callback)
toJSON()
trunc(limit_num[, offset_num])

## RecordSet()

Record Set is a set of records.
Factory pattern: this class cannot be construced using the new keyword. This class is constructed when calling a specific method or attribute, e.g. using module:qm.Store#allRecords to get all the records in the store as a record set.

## Properties

### empty

Checks if the record set is empty. If the record set is empty, then it returns true. Otherwise, it returns false. Type `boolean`.

### length

Returns the number of records in record set. Type `number`.

### store

Returns the store, where the records in the record set are stored. Type module:qm.Store.

### weighted

Checks if the record set is weighted. If the record set is weighted, then it returns true. Otherwise, it returns false. Type `boolean`.

## Methods

### clone() → module:qm.RecordSet

Creates a new instance of the record set.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "Philosophers",
           fields: [
               { name: "Name", type: "string" },
               { name: "Era", type: "string" }
           ]
       }]
    });
    // put some records in the store
    base.store("Philosophers").push({ Name: "Plato", Era: "Ancient philosophy" });
    base.store("Philosophers").push({ Name: "Immanuel Kant", Era: "18th-century philosophy" });
    base.store("Philosophers").push({ Name: "Emmanuel Levinas", Era: "20th-century philosophy" });
    base.store("Philosophers").push({ Name: "Rene Descartes", Era: "17th-century philosophy" });
    base.store("Philosophers").push({ Name: "Confucius", Era: "Ancient philosophy" });
    // create a record set out of the records in store
    var recordSet = base.store("Philosophers").allRecords;
    // clone the record set of the "Philosophers" store
    var philosophers = recordSet.clone();
    base.close();

Returns

  `module:qm.RecordSet`B A copy of the record set.

### deleteRecords(rs) → module:qm.RecordSet

Deletes the records, that are also in the second record set.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "BookWriters",
           fields: [
               { name: "Name", type: "string" },
               { name: "Genre", type: "string" },
               { name: "Books", type: "string_v" }
           ]
       }]
    });
    // set new records in the store
    base.store("BookWriters").push({ Name: "Terry Pratchett", Genre: "Fantasy", Books: ["The Colour of Magic", "Going Postal", "Mort", "Guards! Guards!"] });
    base.store("BookWriters").push({ Name: "Douglas Adams", Genre: "Sci-fi", Books: ["The Hitchhiker's Guide to the Galaxy", "So Long, and Thanks for All the Fish"] });
    base.store("BookWriters").push({ Name: "Fyodor Dostoyevsky", Genre: "Drama", Books: ["Crime and Punishment", "Demons"] });
    base.store("BookWriters").push({ Name: "J.R.R. Tolkien", Genre: "Fantasy", Books: ["The Hobbit", "The Two Towers", "The Silmarillion" ] });
    base.store("BookWriters").push({ Name: "George R.R. Martin", Genre: "Fantasy", Books: ["A Game of Thrones", "A Feast of Crows"] });
    base.store("BookWriters").push({ Name: "J. K. Rowling", Genre: "Fantasy", Books: ["Harry Potter and the Philosopher's Stone"] });
    base.store("BookWriters").push({ Name: "Ivan Cankar", Genre: "Drama", Books: ["On the Hill", "The King of Betajnova", "The Serfs"] });
    // create one record set containing all records of store
    var recordSet = base.store("BookWriters").allRecords;
    // create one record set containing the records with genre "Fantasy"
    var fantasy = base.store("BookWriters").allRecords.filterByField("Genre", "Fantasy");
    // delete the records in recordSet, that are also in fantasy
    recordSet.deleteRecords(fantasy); // returns self, containing only three records: "Douglas Adams", "Fyodor Dostoyevsky" and "Ivan Cankar"
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
rs | module:qm.RecordSet |  | The second record set.

Returns

  `module:qm.RecordSet`B Self. Contains only the records, that are not in `rs`.

### each(callback) → module:qm.RecordSet

Executes a function on each record in record set.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "People",
           fields: [
               { name: "Name", type: "string" },
               { name: "Gender", type: "string" }
           ]
       }]
    });
    // put some records in the store
    base.store("People").push({ Name: "Eric Sugar", Gender: "Male" });
    base.store("People").push({ Name: "Jane Tokyo", Gender: "Female" });
    base.store("People").push({ Name: "Mister Tea", Gender: "Male" });
    // create a record set out of the records of the store
    var recordSet = base.store("People").allRecords;
    // change the Name of all records into "Anonymous"
    recordSet.each(function (rec) { rec.Name = "Anonymous"; }); // returns self, all record's Name are "Anonymous"
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
callback | function() |  | Function to be executed. It takes two parameters: 1. `rec` - The current record. Type module:qm.Record. Warning: Do not use `rec` outside the scope of the callback. An internal optimization re-uses `rec` object between calls to `callback`. 2. `idx` - The index of the current record (optional). Type `number`.

Returns

  `module:qm.RecordSet`B Self.

### filter(callback) → module:qm.RecordSet

Keeps only the records that pass the callback function.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "ArcheryChampionship",
           fields: [
               { name: "Name", type: "string" },
               { name: "ScorePerRound", type: "float_v" }
           ]
       }]
    });
    // set new records in the store
    base.store("ArcheryChampionship").push({ Name: "Robin Hood", ScorePerRound: [50, 48, 48] });
    base.store("ArcheryChampionship").push({ Name: "Oliver Queen", ScorePerRound: [44, 46, 44] });
    base.store("ArcheryChampionship").push({ Name: "Legolas", ScorePerRound: [50, 50, 48] });
    // create a record set out of the records of the store
    var recordSet = base.store("ArcheryChampionship").allRecords;
    // filter the records: which archers have scored 48 points in the third round
    recordSet.filter(function (rec) { return rec.ScorePerRound[2] == 48; }); // keeps only the records, where the score of the third round is equal 48
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
callback | function() |  | The filter function. It takes one parameter: 1. `rec` - The record in the record set. Type module:qm.Record. Returns a `boolean` value.

Returns

  `module:qm.RecordSet`B Self. Contains only the records that pass the callback function.

### filterByField(fieldName, minVal, maxVal) → module:qm.RecordSet

Keeps only the records with a specific value of some field.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "WeatherForcast",
           fields: [
               { name: "Weather", type: "string" },
               { name: "Date", type: "datetime" },
               { name: "TemperatureDegrees", type: "int" },
           ]
       }]
    });
    // put some records in the "WeatherForecast" store
    base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-27T11:00:00", TemperatureDegrees: 19 });
    base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-28T11:00:00", TemperatureDegrees: 22 });
    base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-29T11:00:00", TemperatureDegrees: 25 });
    base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-30T11:00:00", TemperatureDegrees: 25 });
    base.store("WeatherForcast").push({ Weather: "Scattered Showers", Date: "2015-05-31T11:00:00", TemperatureDegrees: 24 });
    base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-06-01T11:00:00", TemperatureDegrees: 27 });
    // get the record set containing the records from the "WeatherForcast" store
    var recordSet = base.store("WeatherForcast").allRecords;
    // filter only the records, where the weather is Mostly Cloudy
    recordSet.filterByField("Weather", "Mostly Cloudy"); // returns self, containing only the records, where the weather is "Mostly Cloudy"
    base.close();

#### Parameters

Name | Type | Optional | Description
--- | --- | --- | ---
fieldName | string |  | The field by which the records will be filtered.
minVal | (string or number) |  | 1. If the field type is a `string`, the exact string to compare. Type `number`. 2. If the field type is a `number`, the minimal value for comparison. Type `number`. 3. TODO Time field
maxVal | number |  | Only in combination with `minVal` for non-string fields. The maximal value for comparison.

Returns

  `module:qm.RecordSet`B Self.
  1. If the `fieldName` field type is `number`, contains only the records with the `fieldName` value between `minVal` and `maxVal`.
  2. If the `fieldName` field type is `string`, contains only the records with `fieldName` equal to `minVal`.

### filterByFq([minFq][, maxFq]) → module:qm.RecordSet

Keeps only the records with weight between two values.

#### Parameters

Name | Type | Optional | Description
--- | --- | --- | ---
minFq | number | Yes | The minimum value.
maxFq | number | Yes | The maximum value.

Returns

  `module:qm.RecordSet`B Self.
  1. Contains only the records of the original with weights between `minFq` and `maxFq`, if parameters are given.
  2. Contains all the records of the original, if no parameter is given.

### filterById([minId][, maxId]) → module:qm.RecordSet

Keeps only records with ids between or equal two values.

#### Example

    // import qm require
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "FrankSinatraGreatestHits",
           fields: [
               { name: "Title", type: "string" },
               { name: "Length", type: "int" }
           ]
       }]
    });
    // put some records in the "FrankSinatraGreatesHits" store
    base.store("FrankSinatraGreatestHits").push({ Title: "Strangers in the Night", Length: 145 });
    base.store("FrankSinatraGreatestHits").push({ Title: "Summer Wind", Length: 173 });
    base.store("FrankSinatraGreatestHits").push({ Title: "It Was a Very Good Year", Length: 265 });
    base.store("FrankSinatraGreatestHits").push({ Title: "Somewhere in Your Heart", Length: 146 });
    base.store("FrankSinatraGreatestHits").push({ Title: "Forget Domani", Length: 156 });
    base.store("FrankSinatraGreatestHits").push({ Title: "Somethin' Stupid", Length: 155 });
    base.store("FrankSinatraGreatestHits").push({ Title: "This Town", Length: 186 });
    // get the records of the store as a record set
    var recordSet = base.store("FrankSinatraGreatestHits").allRecords;
    // from the record set keep the records with indeces between or equal 2 and 5
    recordSet.filterById(2, 5);
    base.close();

#### Parameters

Name | Type | Optional | Description
--- | --- | --- | ---
minId | number | Yes | The minimum id.
maxId | number | Yes | The maximum id.

Returns

  `module:qm.RecordSet`B Self.
  1. Contains only the records of the original with IDs between `minId` and `maxId`, if parameters are given.
  2. Contains all the records of the original, if no parameter is given.

### getMatrix(fieldName) → (module:la.Matrix or module:la.SparseMatrix)

Creates a vector containing the field values of records.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "ArcheryChampionship",
           fields: [
               { name: "Name", type: "string" },
               { name: "ScorePerRound", type: "float_v" }
           ]
       }]
    });
    // set new records in the store
    base.store("ArcheryChampionship").push({ Name: "Robin Hood", ScorePerRound: [50, 48, 48] });
    base.store("ArcheryChampionship").push({ Name: "Oliver Queen", ScorePerRound: [44, 46, 44] });
    base.store("ArcheryChampionship").push({ Name: "Legolas", ScorePerRound: [50, 50, 48] });
    // create a record set of the records in store
    var recordSet = base.store("ArcheryChampionship").allRecords;
    // create a matrix from the "ScorePerRound" field
    // the i-th column of the matrix is the data of the i-th record in record set
    // the matrix will look like
    // 50  44  50
    // 48  46  50
    // 48  44  48
    var matrix = recordSet.getMatrix("ScorePerRound");
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
fieldName | string |  | The field from which to take the values. It's type must be numeric, e.g. `int`, `float`, `float_v`, `num_sp_v`...

Returns

  `(module:la.Matrix or module:la.SparseMatrix)`B The matrix containing the field values of records.

### getVector(fieldName) → module:la.Vector

Creates a vector containing the field values of records.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "TVSeries",
           fields: [
               { name: "Title", type: "string", "primary": true },
               { name: "NumberOfEpisodes", type: "int" }
           ]
       }]
    });
    // add some records in the store
    base.store("TVSeries").push({ Title: "Archer", NumberOfEpisodes: 75 });
    base.store("TVSeries").push({ Title: "The Simpsons", NumberOfEpisodes: 574 });
    base.store("TVSeries").push({ Title: "New Girl", NumberOfEpisodes: 94 });
    base.store("TVSeries").push({ Title: "Rick and Morty", NumberOfEpisodes: 11 });
    base.store("TVSeries").push({ Title: "Game of Thrones", NumberOfEpisodes: 47 });
    // create a record set of the records of store
    var recordSet = base.store("TVSeries").allRecords;
    // create a vector containing the number of episodes for each series
    // the vector will look like [75, 574, 94, 11, 47]
    var vector = recordSet.getVector("NumberOfEpisodes");
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
fieldName | string |  | The field from which to take the values. It's type must be one-dimensional, e.g. `int`, `float`, `string`...

Returns

  `module:la.Vector`B The vector containing the field values of records. The type it contains is dependant of the field type.

### join(joinName[, sampleSize]) → module:qm.RecordSet

Creates a new record set out of the join attribute of records.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing two stores, with join attributes
    var base = new qm.Base({
       mode: "createClean",
       schema: [
       {
           name: "Musicians",
           fields: [
               { name: "Name", type: "string" },
               { name: "Instruments", type: "string_v" }
           ],
           joins: [
               { name: "PlaysIn", type: "index", store: "Bands", inverse: "Members" }
           ]
       },
       {
           name: "Bands",
           fields: [
               { name: "Name", type: "string" },
               { name: "Genre", type: "string" }
           ],
           joins: [
               { name: "Members", type: "index", store: "Musicians", inverse: "PlaysIn" }
           ]
       }]
    });
    // add some new records to both stores
    base.store("Musicians").push({ Name: "Robert Plant", Instruments: ["Vocals"], PlaysIn: [{Name: "Led Zeppelin", "Genre": "Rock" }] });
    base.store("Musicians").push({ Name: "Jimmy Page", Instruments: ["Guitar"], PlaysIn: [{Name: "Led Zeppelin", "Genre": "Rock" }] });
    base.store("Bands").push({ Name: "The White Stripes", Genre: "Rock" });
    // create a record set containing the musicians, that are members of some bend
    // returns a record set containing the records of "Robert Plant" and "Jimmy Page"
    var ledZeppelin = base.store("Bands").allRecords.join("Members");
    // create a record set containing the first musician, that is a member of some band
    // returns a record set containing only one record, which is "Robert Plant" or "Jimmy Page"
    var ledMember = base.store("Bands").allRecords.join("Members", 1);
    base.close();

#### Parameters

Name | Type | Optional | Description
--- | --- | --- | ---
joinName | string |  | The name of the join attribute.
sampleSize | number | Yes | The number of records to be used for construction of the record set.

Returns

  `module:qm.RecordSet`B The record set containing the join records.

### map(callback) → Array of Object

Creates an array of function outputs created from the records in record set.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "People",
           fields: [
               { name: "Name", type: "string" },
               { name: "Gender", type: "string" }
           ]
       }]
    });
    // put some records in the store
    base.store("People").push({ Name: "Eric Sugar", Gender: "Male" });
    base.store("People").push({ Name: "Jane Tokyo", Gender: "Female" });
    base.store("People").push({ Name: "Mister Tea", Gender: "Male" });
    // create a record set out of the records of the store
    var recordSet = base.store("People").allRecords;
    // make an array of record Names
    var arr = recordSet.map(function (rec) { return rec.Name; }); // returns an array: ["Eric Sugar", "Jane Tokyo", "Mister Tea"]
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
callback | function() |  | Function that generates the array. It takes two parameters: 1. `rec` - The current record. Type module:qm.Record. Warning: Do not use `rec` outside the scope of the callback. An internal optimization re-uses `rec` object between calls to `callback`. 2. `idx` - The index of the current record (optional). Type `number`.

Returns

  `Array of Object`B The array created by the callback function.

### reverse() → module:qm.RecordSet

It reverses the record order.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "WeatherForcast",
           fields: [
               { name: "Weather", type: "string" },
               { name: "Date", type: "datetime" },
               { name: "TemperatureDegrees", type: "int" },
           ]
       }]
    });
    // put some records in the "WeatherForecast" store
    base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-27T11:00:00", TemperatureDegrees: 19 });
    base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-28T11:00:00", TemperatureDegrees: 22 });
    base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-29T11:00:00", TemperatureDegrees: 25 });
    base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-30T11:00:00", TemperatureDegrees: 25 });
    base.store("WeatherForcast").push({ Weather: "Scattered Showers", Date: "2015-05-31T11:00:00", TemperatureDegrees: 24 });
    base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-06-01T11:00:00", TemperatureDegrees: 27 });
    // get the record set containing the records from the "WeatherForcast" store
    var recordSet = base.store("WeatherForcast").allRecords;
    // reverse the record order in the record set
    recordSet.reverse(); // returns self, the records in the record set are in the reverse order
    base.close();

Returns

  `module:qm.RecordSet`B Self. Records are in reversed order.

### sample(num) → module:qm.RecordSet

Creates a random sample of records of the record set.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base with one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "Movies",
           fields: [
               { name: "Title", type: "string" },
               { name: "Length", type: "int" },
               { name: "Director", type: "string" }
           ]
       }]
    });
    // put some records in the store
    base.store("Movies").push({ Title: "The Nightmare Before Christmas", Length: 76, Director: "Henry Selick" });
    base.store("Movies").push({ Title: "Jurassic Part", Length: 127, Director: "Steven Spielberg" });
    base.store("Movies").push({ Title: "The Avengers", Length: 143, Director: "Joss Whedon" });
    base.store("Movies").push({ Title: "The Clockwork Orange", Length: 136, Director: "Stanley Kubrick" });
    base.store("Movies").push({ Title: "Full Metal Jacket", Length: 116, Director: "Stanely Kubrick" });
    // create a sample record set of containing 3 records from the "Movies" store
    var sample = base.store("Movies").allRecords.sample(3);
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
num | number |  | The number of records in the sample.

Returns

  `module:qm.RecordSet`B A record set containing the sample records.

### setDiff(rs) → module:qm.RecordSet

Creates the set difference between two record sets.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "BookWriters",
           fields: [
               { name: "Name", type: "string" },
               { name: "Genre", type: "string" },
               { name: "Books", type: "string_v" }
           ]
       }]
    });
    // set new records in the store
    base.store("BookWriters").push({ Name: "Terry Pratchett", Genre: "Fantasy", Books: ["The Colour of Magic", "Going Postal", "Mort", "Guards! Guards!"] });
    base.store("BookWriters").push({ Name: "Douglas Adams", Genre: "Sci-fi", Books: ["The Hitchhiker's Guide to the Galaxy", "So Long, and Thanks for All the Fish"] });
    base.store("BookWriters").push({ Name: "Fyodor Dostoyevsky", Genre: "Drama", Books: ["Crime and Punishment", "Demons"] });
    base.store("BookWriters").push({ Name: "J.R.R. Tolkien", Genre: "Fantasy", Books: ["The Hobbit", "The Two Towers", "The Silmarillion" ] });
    base.store("BookWriters").push({ Name: "George R.R. Martin", Genre: "Fantasy", Books: ["A Game of Thrones", "A Feast of Crows"] });
    base.store("BookWriters").push({ Name: "J. K. Rowling", Genre: "Fantasy", Books: ["Harry Potter and the Philosopher's Stone"] });
    base.store("BookWriters").push({ Name: "Ivan Cankar", Genre: "Drama", Books: ["On the Hill", "The King of Betajnova", "The Serfs"] });
    // create one record set containing all records of store
    var recordSet = base.store("BookWriters").allRecords;
    // create one record set containing the records with genre "Fantasy"
    var fantasy = base.store("BookWriters").allRecords.filterByField("Genre", "Fantasy");
    // create a new record set containing the difference of recordSet and fantasy
    var difference = recordSet.setDiff(fantasy); // returns a record set, containing the records of Douglas Adams, Fyodor Dostoyevsky and Ivan Cankar
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
rs | module:qm.RecordSet |  | The other record set.

Returns

  `module:qm.RecordSet`B The difference between the two record sets.

### setIntersect(rs) → module:qm.RecordSet

Creates the set intersection of two record sets.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base with one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "Movies",
           fields: [
               { name: "Title", type: "string" },
               { name: "Length", type: "int" },
               { name: "Director", type: "string" }
           ]
       }]
    });
    // put some records in the store
    base.store("Movies").push({ Title: "The Nightmare Before Christmas", Length: 76, Director: "Henry Selick" });
    base.store("Movies").push({ Title: "Jurassic Part", Length: 127, Director: "Steven Spielberg" });
    base.store("Movies").push({ Title: "The Avengers", Length: 143, Director: "Joss Whedon" });
    base.store("Movies").push({ Title: "The Clockwork Orange", Length: 136, Director: "Stanley Kubrick" });
    base.store("Movies").push({ Title: "Full Metal Jacket", Length: 116, Director: "Stanely Kubrick" });
    // create a record set out of the records in store, where length of the movie is greater than 110
    var greaterSet = base.store("Movies").allRecords.filterByField("Length", 110, 150);
    // create a record set out of the records in store, where the length of the movie is lesser than 130
    var lesserSet = base.store("Movies").allRecords.filterByField("Length", 0, 130);
    // get the intersection of greaterSet and lesserSet
    var intersection = greaterSet.setIntersect(lesserSet); // returns a record set, containing the movies with lengths between 110 and 130
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
rs | module:qm.RecordSet |  | The other record set.

Returns

  `module:qm.RecordSet`B The intersection of the two record sets.

### setUnion(rs) → module:qm.RecordSet

Creates the set union of two record sets.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "TVSeries",
           fields: [
               { name: "Title", type: "string", "primary": true },
               { name: "NumberOfEpisodes", type: "int" }
           ]
       }]
    });
    // add some records in the store
    base.store("TVSeries").push({ Title: "Archer", NumberOfEpisodes: 75 });
    base.store("TVSeries").push({ Title: "The Simpsons", NumberOfEpisodes: 574 });
    base.store("TVSeries").push({ Title: "New Girl", NumberOfEpisodes: 94 });
    base.store("TVSeries").push({ Title: "Rick and Morty", NumberOfEpisodes: 11 });
    base.store("TVSeries").push({ Title: "Game of Thrones", NumberOfEpisodes: 47 });
    // create a record set out of the records in store, where the number of episodes is lesser than 47
    var lesserSet = base.store("TVSeries").allRecords.filterByField("NumberOfEpisodes", 0, 47);
    // create a record set out of the records in store, where the number of episodes is greater than 100
    var greaterSet = base.store("TVSeries").allRecords.filterByField("NumberOfEpisodes", 100, 600);
    // get the union of lesserSet and greaterSet
    var union = lesserSet.setUnion(greaterSet); // returns a record set, which is the union of the two record sets
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
rs | module:qm.RecordSet |  | The second record set.

Returns

  `module:qm.RecordSet`B The union of the two record sets.

### shuffle([seed]) → module:qm.RecordSet

Shuffles the order of records in the record set.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "WeatherForcast",
           fields: [
               { name: "Weather", type: "string" },
               { name: "Date", type: "datetime" },
               { name: "TemperatureDegrees", type: "int" }
           ]
       }]
    });
    // put some records in the "WeatherForecast" store
    base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-27T11:00:00", TemperatureDegrees: 19 });
    base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-28T11:00:00", TemperatureDegrees: 22 });
    base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-29T11:00:00", TemperatureDegrees: 25 });
    base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-30T11:00:00", TemperatureDegrees: 25 });
    base.store("WeatherForcast").push({ Weather: "Scattered Showers", Date: "2015-05-31T11:00:00", TemperatureDegrees: 24 });
    base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-06-01T11:00:00", TemperatureDegrees: 27 });
    // get the record set containing the records from the "WeatherForcast" store
    var recordSet = base.store("WeatherForcast").allRecords;
    // shuffle the records in the newly created record set. Use the number 100 as the seed for the shuffle
    recordSet.shuffle(100); // returns self, the records in the record set are shuffled
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
seed | number | Yes | Integer.

Returns

  `module:qm.RecordSet`B Self. The records in the record set are in a different order.

### sort(callback) → module:qm.RecordSet

Sorts the records according to the given callback function.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "TVSeries",
           fields: [
               { name: "Title", type: "string", primary: true },
               { name: "NumberOfEpisodes", type: "int" }
           ]
       }]
    });
    // add some records in the store
    base.store("TVSeries").push({ Title: "Archer", NumberOfEpisodes: 75 });
    base.store("TVSeries").push({ Title: "The Simpsons", NumberOfEpisodes: 574 });
    base.store("TVSeries").push({ Title: "New Girl", NumberOfEpisodes: 94 });
    base.store("TVSeries").push({ Title: "Rick and Morty", NumberOfEpisodes: 11 });
    base.store("TVSeries").push({ Title: "Game of Thrones", NumberOfEpisodes: 47 });
    // get the records of the "TVSeries" store as a record set
    var recordSet = base.store("TVSeries").allRecords;
    // sort the records by their number of episodes
    recordSet.sort(function (rec, rec2) { return rec.NumberOfEpisodes < rec2.NumberOfEpisodes; }); // returns self, records are sorted by the number of episodes
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
callback | function() |  | The function used to sort the records. It takes two parameters: 1. `rec` - The first record. 2. `rec2` - The second record. The function return type `boolean`.

Returns

  `module:qm.RecordSet`B Self. The records are sorted according to the `callback` function.

### sortByField(fieldName[, asc]) → module:qm.RecordSet

Sorts the records according to a specific record field.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "TVSeries",
           fields: [
               { name: "Title", type: "string", primary: true },
               { name: "NumberOfEpisodes", type: "int" }
           ]
       }]
    });
    // add some records in the store
    base.store("TVSeries").push({ Title: "Archer", NumberOfEpisodes: 75 });
    base.store("TVSeries").push({ Title: "The Simpsons", NumberOfEpisodes: 574 });
    base.store("TVSeries").push({ Title: "New Girl", NumberOfEpisodes: 94 });
    base.store("TVSeries").push({ Title: "Rick and Morty", NumberOfEpisodes: 11 });
    base.store("TVSeries").push({ Title: "Game of Thrones", NumberOfEpisodes: 47 });
    // get the records of the "TVSeries" store as a record set
    var recordSet = base.store("TVSeries").allRecords;
    // sort the records by their "Title" field in ascending order
    recordSet.sortByField("Title", true); // returns self, record are sorted by their "Title"
    base.close();

#### Parameters

Name | Type | Optional | Description
--- | --- | --- | ---
fieldName | string |  | The field by which the sort will work.
asc | number | Yes | if `asc` > 0, it sorts in ascending order. Otherwise, it sorts in descending order. Defaults to `-1`.

Returns

  `module:qm.RecordSet`B Self. Records are sorted according to `fieldName` and `asc`.

### sortByFq([asc]) → module:qm.RecordSet

Sorts the records according to their weight.

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
asc | number | Yes | If `asc` > 0, it sorts in ascending order. Otherwise, it sorts in descending order. Defaults to `1`.

Returns

  `module:qm.RecordSet`B Self. Records are sorted according to record weight and `asc`.

### sortById([asc]) → module:qm.RecordSet

Sorts the records according to record ID.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "Tea",
           fields: [
               { name: "Name", type: "string" },
               { name: "Type", type: "string"},
               { name: "Origin", type: "string", "null": true  }
           ]
       }]
    });
    // put some records in the "Tea" store
    base.store("Tea").push({ Name: "Tanyang Gongfu", Type: "Black", Origin: "Tanyang" });
    base.store("Tea").push({ Name: "Rou Gui", Type: "White" });
    base.store("Tea").push({ Name: "Tieluohan Tea", Type: "Wuyi", Origin: "Northern Fujian" });
    base.store("Tea").push({ Name: "Red Robe", Type: "Oolong", Origin: "Wuyi Mountains" });
    // get the records of the "Tea" store as a record set
    var recordSet = base.store("Tea").allRecords;
    // sort the records in the record set by their id in descending order
    recordSet.sortById(); // returns self, the records are sorted in descending order (default)
    // sort the records in the record set by their id in ascending order
    recordSet.sortById(1); // returns self, the records are sorted in ascending order
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
asc | number | Yes | If `asc` > 0, it sorts in ascending order. Otherwise, it sorts in descending order. Defaults to `-1`.

Returns

  `module:qm.RecordSet`B Self. Records are sorted according to record ID and `asc`.

### split(callback) → Array of module:qm.RecordSet

Splits the record set into smaller record sets.

#### Example

    // import qm module
    var qm = require("qminer");
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "SocialGames",
           fields: [
               { name: "Title", type: "string" },
               { name: "Type", type: "string" },
               { name: "MinPlayers", type: "int" },
               { name: "MaxPlayers", type: "int" }
           ]
       }]
    });
    // set new records in the store
    base.store("SocialGames").push({ Title: "DungeonsAndDragons", Type: "Role-Playing", MinPlayers: 5, MaxPlayers: 5 });
    base.store("SocialGames").push({ Title: "Dobble", Type: "Card", MinPlayers: 2, MaxPlayers: 8 });
    base.store("SocialGames").push({ Title: "Settlers of Catan", Type: "Board", MinPlayers: 3, MaxPlayers: 4 });
    base.store("SocialGames").push({ Title: "Munchkin", Type: "Card", MinPlayers: 3, MaxPlayers: 6 });
    // create a record set out of the records of the store
    var recordSet = base.store("SocialGames").allRecords;
    // sort the records by MinPlayers in ascending order
    recordSet.sortByField("MinPlayers", true);
    // split the record set by the minimum number of players
    // returns an array containing three record sets: the first containing the "DungeonsAndDragons" record,
    // the second containing the "Settlers of Catan" and "Munchkin" records and the third containing the
    // "Dobble" record
    var arr = recordSet.split(function (rec, rec2) { return rec.MinPlayers < rec2.MinPlayers; });
    base.close();

#### Parameter

Name | Type | Optional | Description
--- | --- | --- | ---
callback | function() |  | The splitter function. It takes two parameters: 1. `rec` - The first record. Type module:qm.Record. 2. `rec2` - The second record. Type module:qm.Record. Returns a `boolean` value.

Returns

  `Array of module:qm.RecordSet`B An array containing the smaller record sets. The records are split according the callback function.

### toJSON() → Object

Returns the record set as a JSON.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "Musicians",
           fields: [
               { name: "Name", type: "string", primary: true },
               { name: "DateOfBirth", type: "datetime" },
               { name: "GreatestHits", type: "string_v" }
           ]
       }]
    });
    // create some records
    base.store("Musicians").push({ Name: "Jimmy Page", DateOfBirth:  "1944-01-09T00:00:00", GreatestHits: ["Stairway to Heaven", "Whole Lotta Love"] });
    base.store("Musicians").push({ Name: "Beyonce", DateOfBirth: "1981-09-04T00:00:00", GreatestHits: ["Single Ladies (Put a Ring on It)"] });
    // create a record set out of the records in the "Musicians" store
    var recordSet = base.store("Musicians").allRecords;
    // create a JSON object out of the record set
    var json = recordSet.toJSON();
    base.close();

Returns

  `Object`B The record set as a JSON.

### trunc(limit_num[, offset_num]) → module:qm.RecordSet

Truncates the first records.

#### Example

    // import qm module
    var qm = require('qminer');
    // create a new base containing one store
    var base = new qm.Base({
       mode: "createClean",
       schema: [{
           name: "Philosophers",
           fields: [
               { name: "Name", type: "string" },
               { name: "Era", type: "string" }
           ]
       }]
    });
    // put some records in the store
    base.store("Philosophers").push({ Name: "Plato", Era: "Ancient philosophy" });
    base.store("Philosophers").push({ Name: "Immanuel Kant", Era: "18th-century philosophy" });
    base.store("Philosophers").push({ Name: "Emmanuel Levinas", Era: "20th-century philosophy" });
    base.store("Philosophers").push({ Name: "Rene Descartes", Era: "17th-century philosophy" });
    base.store("Philosophers").push({ Name: "Confucius", Era: "Ancient philosophy" });
    // create two identical record sets of the "Philosophers" store
    var recordSet1 = base.store("Philosophers").allRecords;
    var recordSet2 = base.store("Philosophers").allRecords;
    // truncate the first 3 records in recordSet1
    recordSet1.trunc(3); // return self, containing only the first 3 records ("Plato", "Immanuel Kant", "Emmanuel Levinas")
    // truncate the first 2 records in recordSet2, starting with "Emmanuel Levinas"
    recordSet2.trunc(2, 2); // returns self, containing only the 2 records ("Emmanuel Levinas", "Rene Descartes")
    base.close();

#### Parameters

Name | Type | Optional | Description
--- | --- | --- | ---
limit_num | number |  | How many records to truncate.
offset_num | number | Yes | Where to start to truncate.

Returns

  `module:qm.RecordSet`B Self.