MulaiMulai sekarang secara gratis

Populate worksheet

The first step of creating a sheet is done; let's populate it with some data now! summ, a data frame with some summary statistics on the two Excel sheets is already coded so you can take it from there.

Latihan ini adalah bagian dari kursus

Introduction to Importing Data in R

Lihat Kursus

Petunjuk latihan

  • Use writeWorksheet() to populate the "data_summary" sheet with the summ data frame.
  • Call saveWorkbook() to store the adapted Excel workbook as a new file, "summary.xlsx".

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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

# Add a worksheet to my_book, named "data_summary"
createSheet(my_book, "data_summary")

# Create data frame: summ
sheets <- getSheets(my_book)[1:3]
dims <- sapply(sheets, function(x) dim(readWorksheet(my_book, sheet = x)), USE.NAMES = FALSE)
summ <- data.frame(sheets = sheets,
                   nrows = dims[1, ],
                   ncols = dims[2, ])

# Add data in summ to "data_summary" sheet
___

# Save workbook as summary.xlsx
___
Edit dan Jalankan Kode