SSDataFrame
public class SSDataFrame<SSElement, FPT> : NSObject, NSCopying, Codable, NSMutableCopying, SSDataFrameContainer where SSElement : Comparable, SSElement : Decodable, SSElement : Encodable, SSElement : Hashable, FPT : Decodable, FPT : Encodable, FPT : SSFloatingPoint
Defines a structure holding multiple SSExamine objects: Each column contains an SSExamine object.
Each COL represents a single SSExamine object. The structure of the dataframe is like a two-dimensional table:
With N = sampleSize:
< COL[0] COL[1] ... COL[columns - 1] >
tags tags[0] tags[1] ... tags[columns - 1]
cnames cnames[0 cnames[1] ... cnames[columns - 1]
ROW0 data[0][0] data[0][1] ... data[0][columns - 1]
ROW1 data[1][0] data[1][1] ... data[1][columns - 1]
... .......... .......... ... ....................
ROWN data[N][0] data[N][1] ... data[N][columns - 1]
-
Required func to conform to Codable protocol
Declaration
Swift
public func encode(to encoder: Encoder) throws
-
Required func to conform to Codable protocol
Declaration
Swift
public required init(from decoder: Decoder) throws
-
Saves the dataframe to filePath using JSONEncoder
Throws
SSSwiftyStatsError.posixError (file can’t be removed), SSSwiftyStatsError.directoryDoesNotExist, SSSwiftyStatsError.fileNotReadableDeclaration
Swift
public func archiveTo(filePath path: String!, overwrite: Bool!) throws -> Bool
Parameters
path
The full qualified filename.
overwrite
If true, file will be overwritten.
-
Initializes a new dataframe from an archive saved by archiveTo(filePath path:overwrite:).
Throws
SSSwiftyStatError.fileNotReadableDeclaration
Swift
public class func unarchiveFrom(filePath path: String!) throws -> SSDataFrame<SSElement, FPT>?
Parameters
path
The full qualified filename.
-
Array containing all SSExamine objects
Declaration
Swift
public var examines: Array<SSExamine<SSElement, FPT>> { get }
-
Number of rows per column (= sample size)
Declaration
Swift
public var sampleSize: Int { get }
-
Returns true if the receiver is equal to
object
.Declaration
Swift
public override func isEqual(_ object: Any?) -> Bool
-
Number of samples (Same as
columns
)Declaration
Swift
public var countOfSamples: Int { get }
-
Number of samples (Same as
countOfSamples
)Declaration
Swift
public var columns: Int { get }
-
Returns true, if the receiver is empty (i.e. there are no data)
Declaration
Swift
public var isEmpty: Bool { get }
-
Required initializer
Declaration
Swift
override public init()
-
Appends a column
Throws
SSSwiftyStatsError examine.sampleSize != self.rowsDeclaration
Swift
public func append(_ examine: SSExamine<SSElement, FPT>, name: String?) throws
Parameters
examine
The SSExamine object
name
Name of column
-
Removes all columns
Declaration
Swift
public func removeAll()
-
Removes a column
Declaration
Swift
public func remove(name: String!) -> SSExamine<SSElement, FPT>?
Parameters
name
Name of column
Return Value
the removed column oe nil
-
Returns the row at a given index
Declaration
Swift
public func row(at index: Int) -> Array<SSElement>
-
Accesses the column at a given index
Declaration
Swift
public subscript(idx: Int) -> SSExamine<SSElement, FPT> { get }
-
Accesses the column named
name
Declaration
Swift
public subscript(name: String) -> SSExamine<SSElement, FPT> { get }
-
Returns a new instance that’s a copy of the receiver.
The returned object is implicitly retained by the sender, who is responsible for releasing it. The copy returned is immutable if the consideration “immutable vs. mutable” applies to the receiving object; otherwise the exact nature of the copy is determined by the class.
Declaration
Swift
public func copy(with zone: NSZone? = nil) -> Any
Parameters
zone
This parameter is ignored. Memory zones are no longer used by Objective-C.
-
Returns a new instance that’s a mutable copy of the receiver.
The returned object is implicitly retained by the sender, who is responsible for releasing it. The copy returned is immutable if the consideration “immutable vs. mutable” applies to the receiving object; otherwise the exact nature of the copy is determined by the class. In fact, that functions does the same as
copy(with:)
Declaration
Swift
public func mutableCopy(with zone: NSZone? = nil) -> Any
Parameters
zone
This parameter is ignored. Memory zones are no longer used by Objective-C.
-
Returns the object returned by
mutableCopy(with:)
where thezone
is nil.This is a convenience method for classes that adopt the NSMutableCopying protocol. An exception is raised if there is no implementation for
mutableCopy(with:)
.Declaration
Swift
public override func mutableCopy() -> Any
-
Returns the object returned by
copy(with:) where the
zone` is nil.This is a convenience method for classes that adopt the NSCopying protocol. An exception is raised if there is no implementation for copy(with:). NSObject does not itself support the NSCopying protocol. Subclasses must support the protocol and implement the copy(with:) method. A subclass version of the copy(with:) method should send the message to super first, to incorporate its implementation, unless the subclass descends directly from NSObject.
Declaration
Swift
public override func copy() -> Any
-
Exports the dataframe as csv
Throws
SSSwiftyStatsErrorDeclaration
Swift
public func exportCSV(path: String!, separator sep: String = ",", useQuotes: Bool = false, firstRowAsColumnName cn: Bool = true, overwrite: Bool = false, stringEncoding enc: String.Encoding = String.Encoding.utf8, atomically: Bool = true) throws -> Bool
Parameters
path
The full path
atomically
Write atomically
firstRowAsColumnName
If true, the row name is equal to the exported SSExamine object. If this object hasn’t a name, an auto incremented integer is used.
useQuotes
If true all fields will be enclosed by quotation marks
overwrite
If true an existing file will be overwritten
stringEncoding
Encoding
Return Value
True if the file was successfully written.
-
Initializes a new DataFrame instance.
Throws
SSSwiftyStatsError if the file doesn’t exist or can’t be accessedThe following example creates a DataFrame object with 4 columns:
let dataString = "Group 1,Group 2,Group 3,Group 4\n6.9,8.3,8.0,5.8\n5.4,6.8,10.5,3.8\n5.8,7.8,8.1,6.1\n4.6,9.2,6.9,5.6\n4.0,6.5,9.3,6.2" var df: SSDataFrame<Double, Double> do { df = try SSDataFrame.dataFrame(fromString: TukeyKramerData_01String, parser: scanDouble) } catch { ... }
Declaration
Swift
public class func dataFrame(fromString: String!, separator sep: String! = ",", firstRowContainsNames cn: Bool = true, parser: (String) -> SSElement?) throws -> SSDataFrame<SSElement, FPT>
Parameters
fromString
A string of objects (mostly numbers) separated by
separator
separator
The separator (delimiter) used. Default = “,”
firstRowContainsNames
Indicates, that the first line contains Column Identifiers.
parser
A function to convert a string to the expected generic type
-
Loads the content of a file using the specified encoding.
Throws
SSSwiftyStatsError if the file doesn’t exist or can’t be accessedDeclaration
Swift
public class func dataFrame(fromFile path: String!, separator sep: String! = ",", firstRowContainsNames cn: Bool = true, stringEncoding: String.Encoding! = String.Encoding.utf8, _ parser: (String) -> SSElement?) throws -> SSDataFrame<SSElement, FPT>
Parameters
path
The path to the file (e.g. ~/data/data.dat)
separator
The separator used in the file
firstRowContainsNames
Indicates, that the first line contains Column Identifiers.
stringEncoding
The encoding to use.
parser
A function to convert a string to the expected generic type