質問

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