How to iteratively name dataset

Here is an example of my code:


sheet_names <- sheets[grepl("String", sheets,

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:

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: