removevars
Deletes variables (columns) from a table or timetable.
Category: Language Fundamentals > Data Types
Syntax
T2 = removevars(T, vars)
Returns T without the variables in vars.
Description
removevars is the readable form of T(:, vars) = []. Asking for a variable that does not exist is an error. To keep a few variables instead of dropping some, index the table with T(:, keep).
Input arguments
T- Table or timetable.
vars- Variable names, indices, or a logical vector.
Output arguments
T2- Table without those variables; the row names or times are kept.
Example
T = table([1;2], [3;4], [5;6], 'VariableNames', {'A','B','C'});
removevars(T, 'B')
removevars(T, [1 3])
Output
ans = 2×2 table
A C
_ _
1 5
2 6
ans = 2×1 table
B
_
3
4