user3310782
user3310782

Reputation: 831

Remove quotes to use result as dataset name

I've got a vector with a long list of dataset names. E.g

myvector<-c('ds1','ds2,'ds3')

I'd like to use the names ds1..ds3 to write a file, taking the file name from the vector. Like this:

write.csv(dataset[i],file=paste(myvector[i],'.csv',sep='')

with dataset being d1...ds3, but without quotes. How can I remove the quotes and refer to the real dataset, and not to the string?

Thanks in advance, p.

Upvotes: 1

Views: 53

Answers (1)

akrun
akrun

Reputation: 887881

You can get the values with get or mget (for multiple objects)

 lst <- mget(myvector)
 lapply(seq_along(lst), function(i) write.csv(lst[[i]], 
            file=paste(myvector[i], '.csv', sep=''))

Upvotes: 2

Related Questions