How to iteratively name dataset

Here is an example of my code:

library(Rcpp)
library(readxl)

Sheets<-readxl::excel_sheets("~/data.xlsx")
sheet_names <- sheets[grepl("String", sheets, ignore.case=TRUE)

for (i in 1:length(sheet_names)){
    dataset[i] <- read_excel("data.xlsx", sheet = sheet_names[i])
}

What I would like this to do is to return a dataset named "dataset1" where i=1 and "dataset2" where i=2 and so on. Alternatively, I would like to use the name of the sheet itself i.e. sheet_names[i] but when attempting to use that it overwrites the strings in the variable.

I would be grateful for any suggestions on this.



Read more here: https://stackoverflow.com/questions/68467682/how-to-iteratively-name-dataset

Content Attribution

This content was originally published by Anto Kiernan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: