0

I would like to do a loop that will generate additional code but do not know how to do this.

i = 1
while (i <= 6) { (some code here)
i=i+1
}

The output would be to create the following new lines of R code in the dame or a new chunk

df1 <- load10X(This path would come from another data frame)
df2 <- load10X(This path would come from another data frame)
df3 <- load10X(This path would come from another data frame)
df4 <- load10X(This path would come from another data frame)
df5 <- load10X(This path would come from another data frame)
df6 <- load10X(This path would come from another data frame)

Any help would be appreciated Dan

  • 3
    Use lists not many separate objects. As this [canonical answer](https://stackoverflow.com/a/24376207/1422451) advises: *Don't ever create `d1` `d2` `d3`, ..., `dn` in the first place. Create a list `d` with `n` elements.* – Parfait Jun 18 '21 at 21:24
  • 2
    Specifically for you, `dfs <- lapply(mylistofdfs, load10X)`, `dfs[[1]]` for 1st item, `dfs[[2]]` for 2nd item, ... – Parfait Jun 18 '21 at 21:25

1 Answers1

0

I agree with Parfait. Here is the code I would use for this:

temp = paste('/path to folder',list.files(path='path to folder'),sep='')
             
myfiles = lapply(temp, load10X)