table
create a table from variables
Syntax
t = table(var1, ..., varN) t = table(m) t = table(st) t = table(..., Name, Value)
Arguments
- var1, ..., varN
vector or matrix with the same number of rows.
Each var can be different type: double, boolean, string, datetime or duration
- m
double, boolean, string, datetime or duration matrix
- st
structure
- Name, Value
'VariableNames': matrix of strings that contains the name of each column of
t
. Default value: ["Var1", ..., "VarN"]'RowNames': indicator for reading the first column as row names
- t
table object.
Description
table is a data type used to store heterogeneous data. Each column of the table represents a variable, named VarN (N: column number) by default. Each variable in a table can have different data type. They must all have the same number of rows. Variable names are unique.
Regarding the extraction and insertion of data, a table is like a matrix: t(i,j) where i and j are indices. In addition to indices, it is possible to use the names of variables and rows to access the data: t.Var1 or t("Var1") where "Var1" is a variable name; t("Row1", "Var1") where "Row1" is a row name and "Var1" is a variable name. It is also possible to mix indices and variable name or row name: t(1,["Var1", "Var3"]) or t("Row1", [1 3]). The data being generally heterogeneous, it will be neccesary to use {} or table to insert data. If they are of the same type, the [] will preferred.
Use the readtable function to create a table from a file. If data contains a timestamp, use the timeseries function instead.
t = table(var1, ..., varN) creates a table from the data variables var1, ..., varN. The variables can be column vector or matrix with the same number of rows. Each var1, ..., varN can be different type.
t = table(m) creates a table from a matrix m. This syntaxe corresponds to t = matrix2table(st).
t = table(st) creates a table from a structure st. This syntaxe corresponds to t = struct2table(st).
t = table(..., Name, Value) can be used to specify the variable names or the row names.
'VariableNames': specify the name of variables. It is a row vector and the number of names must be equal the number of table variables. This data is stored in the properties of the table t in the 'VariableNames' field. For more information, see the Properties section below.
'RowNames': specify the name of rows. The number of names must be equal the number of table rows. This data is stored in the properties of the table t in the 'RowNames' field. For more information, see the Properties section below.
Table Properties
t contains several properties used to describe the index and the variables.
These properties can be accessed/modified by using Properties field of t.
Here is the list of available fields in t.Properties:
Description: contains the description of the table. Default value: "".
VariableNames: contains the variable names of the table. Default value: ["Var1", ..., "VarN"].
VariableDescriptions: contains the variable descriptions of the table. One description by variable. Default value: "".
VariableUnits: contains the variable units of the table. Default value: "".
RowNames: contains the row names of the table. Default value: ""
Examples
t = table(var1, ..., varN) with var1, ..., varN are column vectors
Code = ["AF"; "NA"; "OC"; "AN"; "AS"; "EU"; "SA"]; NameContinent = ["Africa"; "North America"; "Oceania"; "Antarctica"; "Asia"; "Europe"; "South America"]; Area = [30065000; 24256000; 7687000; 13209000; 44579000; 9938000; 17819000]; // in km2 NumberCountry = [54; 23; 14; %nan; 47; 45; 12]; LifeExpectancy = [60; 78; 75; %nan; 72; 75; 74]; // in years t = table(Code, NameContinent, Area, NumberCountry, LifeExpectancy)
t = table(var1, ..., varN, "VariableNames", Value)
Code = ["AF"; "NA"; "OC"; "AN"; "AS"; "EU"; "SA"]; NameContinent = ["Africa"; "North America"; "Oceania"; "Antarctica"; "Asia"; "Europe"; "South America"]; Area = [30065000; 24256000; 7687000; 13209000; 44579000; 9938000; 17819000]; // in km2 NumberCountry = [54; 23; 14; %nan; 47; 45; 12]; LifeExpectancy = [60; 78; 75; %nan; 72; 75; 74]; // in years t = table(Code, NameContinent, Area, NumberCountry, LifeExpectancy, ... "VariableNames", ["Code", "NameContinent", "Area", "NumberCountry", "LifeExpectancy"]) t.Properties // Add a description to the table t.Properties.Description = "table of the 7 continents" // Add variableunits to the table t.Properties.VariableUnits(3) = "km2" t.Properties.VariableUnits($) = "years" t.Properties
t = table(var1, ..., varN, "VariableNames", Value, "RowNames", Value)
Code = ["AF"; "NA"; "OC"; "AN"; "AS"; "EU"; "SA"]; NameContinent = ["Africa"; "North America"; "Oceania"; "Antarctica"; "Asia"; "Europe"; "South America"]; Area = [30065000; 24256000; 7687000; 13209000; 44579000; 9938000; 17819000]; // in km2 NumberCountry = [54; 23; 14; %nan; 47; 45; 12]; LifeExpectancy = [60; 78; 75; %nan; 72; 75; 74]; // in years t = table(Code, NameContinent, Area, NumberCountry, LifeExpectancy, ... "VariableNames", ["Code", "NameContinent", "Area", "NumberCountry", "LifeExpectancy"]) t.Row t.Row = Code t.Code = []; t(["NA", "SA"], :) t = table(NameContinent, Area, NumberCountry, LifeExpectancy, ... "VariableNames", ["NameContinent", "Area", "NumberCountry", "LifeExpectancy"], "RowNames", Code) t.Properties.RowNames t("NA", ["NameContinent", "NumberCountry"])
Access to data in the table
See also
- readtable — create a table from a file
- writetable — write a table to file
- timeseries — create a timeseries - table with time as index
History
Версия | Описание |
2024.0.0 | Introduction in Scilab. |
Report an issue | ||
<< synchronize | Timeseries/Table | table2cell >> |