addvars
Add variables to table or timeseries
Syntax
tout = addvars(tin, var1, ..., varN) tout = addvars(tin, var1, ..., varN, "Before", loc) tout = addvars(tin, var1, ..., varN, "After", loc) tout = addvars(tin, var1, ..., varN, "NewVariableNames", newvarnames) tout = addvars(tin, var1, ..., varN, "Before", loc, "NewVariableNames", newvarnames) tout = addvars(tin, var1, ..., varN, "After", loc, "NewVariableNames", newvarnames)
Arguments
- tin
table or timeseries
- var1, ..., varN
vector or matrix of doubles, strings, booleans, duration or datetime corresponding to variables to add.
- loc
double or string value specifying the location to insert the variables based on "After" or "Before" keywords.
- newvarnames
string scalar or vector containing the names of added variables. It must be used with "NewVariableNames" keyword.
- tout
table or timeseries
Description
tout = addvars(tin, var1, ..., varN) creates tout
from tin
by adding the new variables var1, ..., varN
at the end.
var1, ..., varN
must have the same number of rows as tin
.
tout = addvars(tin, var1, ..., varN, "Before", loc) creates tout
from tin
by adding the new variables var1, ..., varN
before loc
.
loc
can be double or string value. If loc
is a double, then it corresponds to the nth variable
in tin
. If loc
is a string, then it is the name of variable in tin
tout = addvars(tin, var1, ..., varN, "After", loc) creates tout
from tin
by adding the new variables var1, ..., varN
after loc
.
tout = addvars(..., "NewVariableNames", newvarnames) renames added variables
var1, ..., varN to newvarnames
.
Examples
Add variable in table
t = table(["A"; "B"; "C"], [1; 2; 3], [4;5;6], "VariableNames", ["Key", "Value1", "Value2"]) v1 = t.Value1 + t.Value2 t2 = addvars(t, v1) v2 = t.Value2 - t.Value1 t2 = addvars(t, v1, v2)
Add variable in timeseries
ts = timeseries(hours(1:3)', ["A"; "B"; "C"], [1; 2; 3], [4;5;6], "VariableNames", ["Hours", "Key", "Value1", "Value2"]) v = [18;16;17] t2 = addvars(ts, v)
Add variable with "After" and "Before" keywords
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, Area, "VariableNames", ["Code", "Area"]) // add NameContinent variable before Code t2 = addvars(t, NameContinent, "Before", "Code") // to rename t2.Var3 variable, use "NewVariableNames" option t2 = addvars(t, NameContinent, "Before", "Code", "NewVariableNames", "NameContinent") // add NumberCountry and LifeExpectancy variables after Area t3 = addvars(t2, NumberCountry, LifeExpectancy, "After", "Area", "NewVariableNames", ["NumberCountry", "LifeExpectancy"])
See also
- table — create a table from variables
- timeseries — create a timeseries - table with time as index
- removevars — Remove variables from table or timeseries
History
Version | Description |
2025.1.0 | Introduction in Scilab. |
Report an issue | ||
<< Timeseries/Table | Timeseries/Table | cell2table >> |