Dataframe package: Difference between revisions

Jump to navigation Jump to search
923 bytes added ,  27 February 2015
no edit summary
mNo edit summary
No edit summary
Line 12: Line 12:


A simple example:
A simple example:
truc={"Id", "Name", "Type";1, "onestring", "bla"; 2, "somestring", "foobar";}
truc =
{
  [1,1] = Id
  [2,1] =  1
  [3,1] =  2
  [1,2] = Name
  [2,2] = onestring
  [3,2] = somestring
  [1,3] = Type
  [2,3] = bla
  [3,3] = foobar
}
>> tt=dataframe(truc)
tt = dataframe with 2 rows and 3 columns
_1    Id      Name  Type
Nr double      char  char
  1      1  onestring    bla
  2      2 somestring foobar
The first cell line is intended to contain column names; the rest is column content. The type is automatically inferred from the cell content. Now let us select one column by its name:
>> tt(:, 'Name')
ans = dataframe with 2 rows and 1 columns
_1      Name
Nr      char
1  onestring
2 somestring
In this case, a sub-dataframe is returned. Struct-like indexing is also implemented:
>> tt.Id
ans =
  1
  2
When the output is a vector and can be simplified to something simple ... it is.
75

edits

Navigation menu