renamevars
Renames variables of a table or timetable.
Category: Language Fundamentals > Data Types
Syntax
T2 = renamevars(T, vars, newnames)
Gives the variables vars the names in newnames.
Description
The new names must be valid and distinct from the other variable names. Renaming leaves data and order unchanged. It is equivalent to editing T.Properties.VariableNames, but works on a subset by name.
Input arguments
T- Table or timetable.
vars- Names or indices of the variables to rename.
newnames- Text, string array or cell array of new names; one per variable in
vars.
Output arguments
T2- Table with the new names and the same data.
Example
T = table([1;2], [3;4], 'VariableNames', {'A','B'});
renamevars(T, 'A', 'Alpha')
renamevars(T, {'A','B'}, {'X','Y'})
Output
ans = 2×2 table
Alpha B
_____ _
1 3
2 4
ans = 2×2 table
X Y
_ _
1 3
2 4