Skip to content

Saving lists to excel tabs #117

Description

@StatsRhian

You can save each cut of the diamonds dataset to a different tab (sheet) in a single Excel file using the writexl or openxlsx package in R. Here's a programmatic approach using writexl for simplicity:

library(ggplot2)
library(dplyr)
library(writexl)

data("diamonds")
diamonds_split <- split(diamonds, diamonds$cut)
write_xlsx(diamonds_split, path = "diamonds_by_cut.xlsx")

split(): Splits the dataset into a list of data frames by cut. The names of the list (Ideal, Premium, etc.) become the sheet names automatically.
write_xlsx(): Takes the list and writes each element to a separate sheet in a single Excel file.

Each sheet will correspond to a different diamond cut (Ideal, Premium, Good, Very Good, Fair).
If you need more customization (like formatting, adding formulas, etc.), the openxlsx package would be ideal, but for straightforward tabbed exports, writexl is quick and clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions