Вопрос

So I use

filenames <- list.files(path="my path", pattern="*.csv")

and then I use assign() and read.csv() to attached an unknown list of .csv in whatever "my path" is.

filename <- c("myFileA","myFileB", "myFileC")

Now myFileA, and myFileB, and myFileC exist as a data frame since I loaded them in.

How to use the filename which contains eg. "myFileA" to pull up data frame myFileA or the other vars?

Basically, I want to manipulate the variables, but because the filenames change, I really have this variable which contains the names:

for (i in filename){

#do something with the dataframe i, BUT
#as is, i is a string "myFileA"
#how to use "myFileA" to pull up dataframe myFileA?

}
Это было полезно?

Решение

The docs for get say it will, "Search by name for an object"

for (i in filename){

#do something with the dataframe
df <- get(i)

}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top