TimeData¶
Access metadata¶
-
idx
(td::AbstractTimedata)¶ Get time index as array.
-
names
(td::AbstractTimedata)¶ Get column names.
-
idxtype
(td::AbstractTimedata)¶ Get type of
idx
.
Access data as Array¶
-
get
(td::AbstractTimedata, idx1::Int, idx2::Int)¶ Get single entry [idx1, idx2] of TimeData object.
-
get
(td::AbstractTimedata) Get all entries of TimeData object as
Array
through comprehension.
-
core
(td::AbstractTimedata)¶ Equal to
get
except forTimematr
.
-
core
(tm::Timematr) Return data as
Array{Float64}
.
-
getAs
(tn::AbstractTimedata, typ::Type=Any, replaceNA=NA)¶ Get all entries as
Array
. In order to avoidArray{Any, 2}
as outcome, the entries can be promoted to a givenType
through argumenttyp
. Missing values can be dealt with through a third argumentreplaceNA
, which replaces occurringNAs
. For example,Timenum
tm
can be transformed toArray{Float64, 2}
through:getAs(tm, Float64, NaN)
.
Access data as DataFrame¶
-
convert
(::DataFrame, td::AbstractTimedata)¶ Convert
Timedata
object toDataFrame
by prepending index column as column :idx.
Dealing with NAs
¶
-
complete_cases
(td::AbstractTimedata)¶ Return
Array{Bool}
withtrue
for rows withoutNA
values.
-
narm
(td::AbstractTimedata)¶ Get complete cases: return copy of td with all rows removed that were containing
NA
.
-
rmDatesOnlyNAs
(tn::AbstractTimedata)¶ Remove all dates that contain strictly missing values
NA
. Required format, for example, for plotting with Gadfly.
Show entries¶
Accessing entries through getindex
methods will always preserve a
rectangular table data structure: the output is an intersection of a
subset of indices with a subset of columns. In contrast,
showEntries
methods allow to access data without rectangular
structure as stacked data. This way, for example, entry (1,2) and
entry (2,1) could be jointly accessed, without simultaneously
returning entries (1,1) and (2,2). The output of showEntries
always is of type Timedata
, with columns variable
and
value
.
-
showEntries
(td::AbstractTimedata, f::Function; sort="dates")¶ Show all entries where function f returns
true
. By default, return values in row major order: for each date try all variables. Column major order can be achieved throughsort="variables"
.
-
showEntries
(td::AbstractTimedata, singleInd::Array{Int}) Show entries given by linear indexing.
-
showEntries
(td::AbstractTimedata, rowInds::Array{Int}, colInds::Array{Int}) Show entries given by subscript indexing.
-
showEntries
(td::AbstractTimedata, td2::AbstractTimedata) Show entries by element-wise logical indexing.
Editing entries¶
-
setNA!(td::AbstractTimedata, rowIdx::Int, colIdx::Int)
Set a given entry to
NA
. Could require change of column type toDataArray
. Throws error forTimematr
.
-
setindex!(td::Timedata, value::Any, rowIdx::Int, colIdx::Int)
Set entry given by subscript indexing to a given value.
-
setindex!(td::AbstractTimenum, value::Any, rowIdx::Int, colIdx::Int)
Set entry given by subscript indexing to a given value.
-
impute!(td::AbstractTimedata, with="last")
Replace
NA
with some value. Implemented options arelast
to use the last available observation,next
to use the next available option,zero
to insert a value of 0 for eachNA
.single last
only uses the last observation if there is a singleNA
in succession. For two or more successive values ofNA
no imputation occurs. A singleNA
in the last row will be treated as if observations would follow, so that it gets replaced. Consecutive occurrences ofNA
at the beginning of the sample will be left untouched with optionslast
andsingle last
. Same holds for consecutive occurrences ofNA
at the end of the sample for optionnext
.
Basic functions¶
-
size
(tn::AbstractTimedata)¶
-
size
(tn::AbstractTimedata, ind::Int)
-
ndims
(tn::AbstractTimedata)¶
Testing object properties¶
-
isequal
(tn::AbstractTimedata, tn2::AbstractTimedata)¶ Test for equal indices, names, types and values.
NA
is equal toNA
. Output is a single value of typeBool
.
-
isequalElw
(tn::AbstractTimedata, tn2::AbstractTimedata)¶ Element-wise comparison with
isequal
. ReturnsTimedata
with boolean values.
-
==(tn::AbstractTimedata, tn2::AbstractTimedata)
Test for equal indices, names, types and values.
NA
is not counted as equal toNA
. Output is a single value of typeBool
.
-
.==(tn::AbstractTimedata, tn2::AbstractTimedata)
Element-wise test for equal values:
NA
is not counted as equal toNA
. ReturnsTimedata
with boolean values, or error if meta-data is not matching.
-
isapprox
(tn::AbstractTimedata, tn2::AbstractTimedata)¶ Test for equal indices, names, types and approximately equal values. Alleviates unit tests for values of type
Float
. Output is a single value of typeBool
.
-
equMeta
(td1::AbstractTimedata, td2::AbstractTimedata)¶ Test for equal meta-data: type, column names and indices. Output is a single value of type
Bool
.
-
equColMeta
(td1::AbstractTimedata, td2::AbstractTimedata)¶ Test for equal meta-data of columns (dates are left unconsidered): type and column names. Output is a single value of type
Bool
.
-
isnaElw
(td::AbstractTimedata)¶ Element-wise testing for
NA
. Returns boolean values as Timedata object.
Date formatting functions¶
-
datesAsStrings
(dats::Array{Date, 1})¶ Convert vector of dates into
Array{ASCIIString, n}
.
-
datesAsStrings
(tm::AbstractTimedata) Take
TimeData
object and convert its vector of dates intoArray(ASCIIString, n)
.
-
datesAsNumbers
(dats::Array{Date, 1})¶ Convert vector of dates into
Array{Float64, n}
.
-
datesAsNumbers
(tm::AbstractTimedata) Take
TimeData
object and convert its vector of dates into numbers:Array{Float64, n}
forDate
andDateTime
entries.
Type preserving functions¶
-
hcat
(inst::AbstractTimedata, inst2::AbstractTimedata)¶ Horizontal concatenation of TimeData objects. Requires objects to be of equal type with completely equal time indices. Result will be of same type as input arguments.
-
hcat
(inst::AbstractTimedata...) Variable argument extension of
hcat
.
-
vcat
(inst::AbstractTimedata, inst2::AbstractTimedata)¶ Vertical concatenation of TimeData objects. Requires objects to be of equal type with equal column names and equal time index types. Result will be of same type as input arguments.
-
vcat
(inst::AbstractTimedata...) Variable argument extension of
vcat
.
-
flipud
(inst::AbstractTimedata)¶ Flip
TimeData
object upside down.
Conversion functions¶
-
asArrayOfEqualDimensions
(arr::Array, td::AbstractTimedata)¶ Extend row or column vector to two-dimensional array through copying values.
-
asTd
(arr::Array, td::Timedata)¶ Extend row or column vector to size of
Timedata
object similar torepmat
and return it asTimedata
object with equal index and names.
-
asTn
(arr::Array, td::Timenum)¶ Extend row or column vector to size of
Timenum
object similar torepmat
and return it asTimenum
object with equal index and names.
-
asTm
(arr::Array, td::Timematr)¶ Extend row or column vector to size of
Timematr
object similar torepmat
and return it asTimematr
object with equal index and names.
-
convert
(::Type{AbstractTimedata}, ta::TimeArray) Convert
TimeArray
toTimeData
object.
DataFrame extensions¶
-
composeDataFrame
(vals, nams)¶ Compose DataFrame from Array and column names.
-
round
(df::DataFrame, nDgts::Int)¶ Return DataFrame with rounded values. DataFrame entries must be numeric.
-
round
(df::DataFrame) Return DataFrame with values rounded to two significant digits. DataFrame entries must be numeric.
-
@roundDf(expr::Expr)
Display rounded DataFrame. Works with non numeric values also.
Display functions¶
-
display
(tn::AbstractTimedata)¶ Timedata display function in standard REPL.
-
writemime
(io::IO, ::MIME"text/html", td::AbstractTimedata)¶ Timedata display function in ijulia.
-
writemime
(io::IO, ::MIME"text/html", tm::AbstractTimematr) Timematr display function in ijulia. Values are rounded due to parsimony.
-
@table(title::String, expr::Union(Expr, Symbol))
Display expression or symbol in HTML with blue title header.
-
str
(tn::AbstractTimedata)¶ More detailled display function similar to R syntax.
Statistics functions¶
-
mean
(tm::AbstractTimematr, dim::Int = 1)¶ Return mean column values as DataFrame.
-
rowmeans
(tm::AbstractTimematr)¶ Return mean row values as Timematr.
-
prod
(tm::AbstractTimematr, dim::Int = 1)¶ Return product of column values as DataFrame.
-
rowprods
(tm::AbstractTimematr)¶ Return product of row values as Timematr.
-
sum
(tm::AbstractTimematr, dim::Int = 1)¶ Return sum of columns as DataFrame.
-
rowsums
(tm::AbstractTimematr)¶ Return sum of rows as Timematr.
-
cov
(tm::AbstractTimematr)¶ Return covariance matrix as DataFrame.
-
cor
(tm::AbstractTimematr)¶ Return correlation matrix as DataFrame.
-
std
(tm::AbstractTimematr)¶ Return empirical standard deviation for each column as DataFrame.
-
std
(tm::AbstractTimematr, dim::Integer) Return empirical standard deviation for each column as DataFrame.
-
minimum
(tm::AbstractTimematr)¶ Return minimum value as single value.
-
minimum
(tm::AbstractTimematr, dim::Integer) Return minimum values of each column as DataFrame.
-
cumsum
(tm::AbstractTimematr, dim::Integer)¶ Calculate cumulative sums column-wise and return result as Timematr.
-
cumprod
(tm::AbstractTimematr, dim::Integer)¶ Calculate cumulative products column-wise and return result as Timematr.
-
rowstds
(tm::AbstractTimematr)¶ Return empirical standard deviation for each row as Timematr.
-
geomMean
(x::AbstractTimematr; percent = true)¶ Calculate geometric mean for AbstractTimedata.
-
geomMean
(x; percent = true) Calculate geometric mean for Array.
-
movAvg
(tm::AbstractTimematr, nPeriods::Integer)¶ Calculate moving average.
I/O¶
-
readTimedata
(filename::String)¶ Load csv and parse date column as
idx
.
-
writeTimedata
(filename::String, td::AbstractTimedata)¶ Write TimeData object to csv file.
Join functions¶
For the case of monotonically increasing index values, join operations can be speeded up. The following join implementations exist. All return a Timedata object.
-
joinSortedIdx_inner
(td1::AbstractTimedata, td2::AbstractTimedata)¶ Inner join of object indices.
-
joinSortedIdx_left
(td1::AbstractTimedata, td2::AbstractTimedata)¶ Left join of object indices.
-
joinSortedIdx_right
(td1::AbstractTimedata, td2::AbstractTimedata)¶ Right join of object indices.
-
joinSortedIdx_outer
(td1::AbstractTimedata, td2::AbstractTimedata)¶ Outer join of object indices.