Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

15. Getting Your Data into Shape > Deleting a Column from a Data Frame

Deleting a Column from a Data Frame

Problem

You want to delete a column from a data frame.

Solution

Assign NULL to that column:

data$badcol <- NULL

Discussion

You can also use the subset() function and put a - (minus sign) in front of the column(s) to drop:

# Return data without badcol
data <- subset(data, select = -badcol)

# Exclude badcol and othercol
data <- subset(data, select = c(-badcol, -othercol))

See Also

Getting a Subset of a Data Frame for more on getting a subset of a data frame.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint