My Original idea is to have a variable (like an R Data Frame type). So
that the columns would have names (i.e the table column names), and I
can access columns by name.
So that for example, if I have a valiable df (a dataframe), with columns
"sex", "smoke", I can extract either of the columns like so:
df["sex",] or df[,"smoke]
Anyway, the main point being that a dataframe contains a list of records
structures (with named columns) - very similar to that of a database
table. I want to be able to create such a structure in SciLab.
The data types held in each of this column vectors (i.e. each field in
the record structure are of type : string, real number, integer or
boolean. In R, an element in the dataframe can also contain another
dataframe - i.e. one of the columns of a dataframe can itself have a
nested dataframe in each of its elements - this allows one to build
nested, heirarchical structures.
I would like to replicate this in SciLab, and would be very grateful for
anyone who can help show me how to do this, or at least pointers on how
to create such a composite structure, if SciLab does not support
anything like data frames.
If you are using a data base with fixed data, establish a typed list to
represent one record (this is analogous to a structure in C or C++), and
store the data base as an array of that type.
You can make a list (or typed list) as an element of another list -- but
it sounds like you're trying to build a relational database, in which case
you may do better to store a _reference_ to a record in another array.
Or, figure out how to link to external programs (it can be done), write an
interface into a real database application, and don't reinvent the wheel.
--
Tim Wescott
Control systems and communications consulting
http://www.wescottdesign.com
Need to learn how to apply control theory in your embedded system?
"Applied Control Theory for Embedded Systems" by Tim Wescott
Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
Hi Tim, thanks very much for the above guidlines on how to approach
this. I have the following further questions (I apologize for asking so
many questions, its just that I am starting out with SciLab and the
existing documentation I have seen so far does not answer these
questions directly):
1). Could you please provide a simple example of how to create a typed
list that represents a table that contains the following columns :
"sex", "smoker", "age", "weight", "height", "num children". The data
types for the columns are :
string ("male", "female"), boolean, real number, real number, real
number, integer
2). Could you please provide an example of how may I create an array of
such a list to replicate a database ?
3). Could you please provide an example of how I may extract columns
from the array of type lists (by the column name), and combine those
columns into a Matrix, so that I can use the Matrices within SiLab?
4). Could you please provide an example on how to access an element in
the array by :
(i) row number, column name
(ii) row number, column number
4). You mentioned _reference_ in your last response. I have tried both
help and apropos with "reference", and no results were returned, could
you please provide further on a reference, and also, could you please
provide an example of how I can create an array of typed list where one
"column" containes another typed list ?
Many, many thanks in advance
Tim Wescott wrote:
Hi Tim, thanks very much for the above guidlines on how to approach
this. I have the following further questions (I apologize for asking so
many questions, its just that I am starting out with SciLab and the
existing documentation I have seen so far does not answer these
questions directly):
1). Could you please provide a simple example of how to create a typed
list that represents a table that contains the following columns :
"sex", "smoker", "age", "weight", "height", "num children". The data
types for the columns are :
string ("male", "female"), boolean, real number, real number, real
number, integer
2). Could you please provide an example of how may I create an array of
such a list to replicate a database ?
3). Could you please provide an example of how I may extract columns
from the array of type lists (by the column name), and combine those
columns into a Matrix, so that I can use the Matrices within SiLab?
4). Could you please provide an example on how to access an element in
the array by :
(i) row number, column name
(ii) row number, column number
5). Last but not the least, you mentioned _reference_ in your last
entry = tlist(['healthdata', 'sex', 'smoker', 'age', 'weight', ..
'height', 'children'], ..
"male", %T, 47, 125, 72, 10); // busy guy
Note that you could make a function out of this, sort of like a constructor:
function d = healthdata(sex, smoker, age, weight, height, children)
d= tlist(['healthdata', 'sex', 'smoker', 'age', 'weight', ..
'height', 'children'], ..
sex, smoker, age, weight, height, children);
endfunction
>
> 2). Could you please provide an example of how may I create an array of
> such a list to replicate a database ?
I had _thought_ that you could just stick this in an array, because that
works for transfer functions. I was wrong: you have to do some operator
overloading to define your syntax. This is still doable, but you'll
have to spelunk a bit (search for %r_f_r in the source code -- it's what
lets you stick a transfer function into an array).
>
> 3). Could you please provide an example of how I may extract columns
> from the array of type lists (by the column name), and combine those
> columns into a Matrix, so that I can use the Matrices within SiLab?
>
You'd probably have to do that with a function that steps through the
array, selecting your column element. If you understood Scilab operator
overloading syntax you should be able to do this as a native operation
-- but I don't know how to do it.
> 4). Could you please provide an example on how to access an element in
> the array by :
> (i) row number, column name
An item H would be accessed by H.sex, H.age, H.children, etc. To access
an array item you'd do it as HH(row).sex, HH(row).age, etc.
> (ii) row number, column number
Dunno. You're back to writing a function, probably, and I don't know if
you could overload it or not.
>
> 4). You mentioned _reference_ in your last response. I have tried both
> help and apropos with "reference", and no results were returned, could
> you please provide further on a reference, and also, could you please
> provide an example of how I can create an array of typed list where one
> "column" containes another typed list ?
You'd have to reference a named type, with some defined (by you) syntax
for querying it, then build up strings to execute.
>
> Many, many thanks in advance
Really, by the time you're done I think you'd be better off making an
interface DLL that'll let you do structured queries to a database
engine. You'll do the same amount of work to get started, and have a
much more polished application in the end.
--
Tim Wescott
Wescott Design Services
http://www.wescottdesign.com
Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" gives you just what it says.
See details at http://www.wescottdesign.com/actfes/actfes.html