Get Started

Renaming sheets

Come to think of it, "data_summary" is not an ideal name. As the summary of these excel sheets is always data-related, you simply want to name the sheet "summary".

The code to build a connection to "urbanpop.xlsx" and create my_book is already provided for you. It refers to an Excel file with 4 sheets: the three data sheets, and the "data_summary" sheet.

This is a part of the course

“Introduction to Importing Data in R”

View Course

Exercise instructions

  • Use renameSheet() to rename the fourth sheet to "summary".
  • Next, call getSheets() on my_book to print out the sheet names.
  • Finally, make sure to actually save the my_book object to a new Excel file, "renamed.xlsx".

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Build connection to urbanpop.xlsx: my_book
my_book <- loadWorkbook("urbanpop.xlsx")

# Rename "data_summary" sheet to "summary"
___

# Print out sheets of my_book
___

# Save workbook to "renamed.xlsx"
___

This exercise is part of the course

Introduction to Importing Data in R

BeginnerSkill Level
4.2+
26 reviews

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 sheets
Exercise 9: Removing sheets

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free