Delete variables from table or timetable (2024)

Delete variables from table or timetable

collapse all in page

Syntax

T2 = removevars(T1,vars)

Description

example

T2 = removevars(T1,vars) deletes the table variables specified by vars and copies the remaining variables to T2. You can specify variables by name, by position, or using logical indices.

For example, to remove table variable var3, use T2 = removevars(T1,'var3').

Delete variables from table or timetable (1)

Examples

collapse all

Remove Variable

Open Live Script

Create a table and remove variables one at a time. You can specify variables by name or by position in the table.

Read data from a spreadsheet into a table. Display the first three rows.

 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'}

Remove the variable that is named Region.

T2 = removevars(T1,'Region');head(T2,3)
 OutageTime Loss Customers RestorationTime Cause ________________ ______ __________ ________________ ________________ 2002-02-01 12:18 458.98 1.8202e+06 2002-02-07 16:50 {'winter storm'} 2003-01-23 00:49 530.14 2.1204e+05 NaT {'winter storm'} 2003-02-07 21:15 289.4 1.4294e+05 2003-02-17 08:14 {'winter storm'}

Remove the fourth variable from T2.

T3 = removevars(T2,4);head(T3,3)
 OutageTime Loss Customers Cause ________________ ______ __________ ________________ 2002-02-01 12:18 458.98 1.8202e+06 {'winter storm'} 2003-01-23 00:49 530.14 2.1204e+05 {'winter storm'} 2003-02-07 21:15 289.4 1.4294e+05 {'winter storm'}

Specify Multiple Variables

Open Live Script

Remove multiple table variables using the removevars function. You can specify variables by name or by position.

Read data from a spreadsheet into a table.

T1 = readtable('outages.csv');head(T1,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'}

Remove the variables named Loss and Customers. Specify names using a cell array of character vectors.

T2 = removevars(T1,{'Loss','Customers'});head(T2,3)
 Region OutageTime RestorationTime Cause _____________ ________________ ________________ ________________ {'SouthWest'} 2002-02-01 12:18 2002-02-07 16:50 {'winter storm'} {'SouthEast'} 2003-01-23 00:49 NaT {'winter storm'} {'SouthEast'} 2003-02-07 21:15 2003-02-17 08:14 {'winter storm'}

Remove the first and fourth variables, using a numeric array to indicate their positions in T2.

T3 = removevars(T2,[1 4]);head(T3,3)
 OutageTime RestorationTime ________________ ________________ 2002-02-01 12:18 2002-02-07 16:50 2003-01-23 00:49 NaT 2003-02-07 21:15 2003-02-17 08:14

Input Arguments

collapse all

T1Input table
table | timetable

Input table, specified as a table or timetable.

varsVariables in input table
string array | character vector | cell array of character vectors | pattern scalar | numeric array | logical array

Variables in the input table, specified as a string array, character vector, cell array of character vectors, pattern scalar, numeric array, or logical array.

Example: T2 = removevars(T1,2) removes the second table variable.

Example: T2 = removevars(T1,'Date') removes the table variable named Date.

Example: T2 = removevars(T1,{'Latitude','Longitude','Elevation'}) removes the table variables named Latitude, Longitude, and Elevation.

Extended Capabilities

Version History

Introduced in R2018a

See Also

addvars | mergevars | movevars | splitvars | renamevars

Topics

  • Add, Delete, and Rearrange Table Variables
  • Add and Delete Table Rows
  • Access Data in Tables
  • Rename and Describe Table Variables
  • Clean Messy and Missing Data in Tables

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Delete variables from table or timetable (2)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Delete variables from table or timetable (2024)
Top Articles
Latest Posts
Article information

Author: Saturnina Altenwerth DVM

Last Updated:

Views: 5844

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Saturnina Altenwerth DVM

Birthday: 1992-08-21

Address: Apt. 237 662 Haag Mills, East Verenaport, MO 57071-5493

Phone: +331850833384

Job: District Real-Estate Architect

Hobby: Skateboarding, Taxidermy, Air sports, Painting, Knife making, Letterboxing, Inline skating

Introduction: My name is Saturnina Altenwerth DVM, I am a witty, perfect, combative, beautiful, determined, fancy, determined person who loves writing and wants to share my knowledge and understanding with you.