timetable.convertvars
timetable: ttB = convertvars (ttA, vars, dataType)
Convert variables of a timetable to a given type.
ttB = convertvars (ttA, vars, dataType)
converts each variable in vars, which may be named, numbered,
selected by a logical vector or picked out by a vartype.
dataType is a type name or a function handle that performs the
conversion.
The row times are not a data variable and cannot be converted; assign
to tt.Properties.RowTimes to change them.
See also: renamevars, timetable
Source Code: timetable
convertvars changes the type of chosen variables, by type name or by a function handle. The row times are not a data variable and are left for Properties.RowTimes to change.
t0 = datetime (2024, 1, 1);
TT = timetable ([1; 2; 3], {'a'; 'b'; 'c'}, 'RowTimes', ...
t0 + hours (0:2)', 'VariableNames', {'Cast', 'Site'})
TT =
3x2 timetable
Time Cast Site
____________________ ____ _____
01-Jan-2024 00:00:00 1 {'a'}
01-Jan-2024 01:00:00 2 {'b'}
01-Jan-2024 02:00:00 3 {'c'}
C = convertvars (TT, 'Site', 'categorical'); class (C.Site)
ans = categorical
C.Properties.TimeStep
ans = duration 01:00:00