Removing sheets
After presenting the new Excel sheet to your peers, it appears not everybody is a big fan. Why summarize sheets and store the info in Excel if all the information is implicitly available? To hell with it, just remove the entire fourth sheet!
This is a part of the course
“Introduction to Importing Data in R”
Exercise instructions
- Build a connection to
"renamed.xlsx"
, the Excel file that you've built in the previous exercise; it's available in your working directory. Store this connection asmy_book
. - Use
removeSheet()
to remove the fourth sheet frommy_book
. The sheet name is"summary"
. Recall thatremoveSheet()
accepts either the index or the name of the sheet as the second argument. - Save the resulting workbook,
my_book
, to a file"clean.xlsx"
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Build connection to renamed.xlsx: my_book
___
# Remove the fourth sheet
___
# Save workbook to "clean.xlsx"
___
This exercise is part of the course
Introduction to Importing Data in R
In this course, you will learn to read CSV, XLS, and text files in R using tools like readxl and data.table.
Beyond importing data from Excel, you can take things one step further with XLConnect. Learn all about it and bridge the gap between R and Excel.
Exercise 1: Reading sheetsExercise 2: Connect to a workbookExercise 3: List and read Excel sheetsExercise 4: Customize readWorksheetExercise 5: Adapting sheetsExercise 6: Add worksheetExercise 7: Populate worksheetExercise 8: Renaming sheetsExercise 9: Removing sheetsWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.