convertvars
Convert table or timetable variables to specified data type
Description
converts specified variables of the input table or timetable to a specified data type. The
remaining variables of the table or timetable are unchanged.T2 = convertvars(T1,vars,dataType)
While you can specify dataType as the name of a data type, you also
can specify it as a function handle. In that case, it is a handle to a function that
converts or otherwise modifies the variables specified by vars.
Similarly, vars can contain variable names or positions of variables in
T1, or it can be a handle to a function that identifies
variables.
Examples
Input Arguments
Output Arguments
Alternative Functionality
You can also convert table and timetable variables
by using the VariableTypes property. Unlike
convertvars, the property enables you to convert different variables to
different data types. (since R2024b)
For example, assign new data types to the variables of table T so that
the first variable is a categorical array and the last variable is a string array.
T = readtable("outages.csv");
head(T,3)
Region OutageTime Loss Customers RestorationTime Cause
_____________ ________________ ______ __________ ________________ ________________
{'SouthWest'} 2002-02-01 12:18 458.98 1.8202e+06 2002-02-07 16:50 {'winter storm'}
{'SouthEast'} 2003-01-23 00:49 530.14 2.1204e+05 NaT {'winter storm'}
{'SouthEast'} 2003-02-07 21:15 289.4 1.4294e+05 2003-02-17 08:14 {'winter storm'}
T.Properties.VariableTypes = ["categorical" "datetime" "double" "double" "datetime" "string"]; head(T,3)
Region OutageTime Loss Customers RestorationTime Cause
_________ ________________ ______ __________ ________________ ______________
SouthWest 2002-02-01 12:18 458.98 1.8202e+06 2002-02-07 16:50 "winter storm"
SouthEast 2003-01-23 00:49 530.14 2.1204e+05 NaT "winter storm"
SouthEast 2003-02-07 21:15 289.4 1.4294e+05 2003-02-17 08:14 "winter storm"
Extended Capabilities
Version History
Introduced in R2018b
See Also
addvars | mergevars | removevars | splitvars | movevars | renamevars
