2

I have a vector a=0.01

Then I create a mat<-matrix(data=NA,ncol=10,nrow=10)

I rename the matrix by:

assign(x = paste("mat", a, sep = "_"), value = mat)

The resulting variable will be called mat_0.01

Then I would like to save this variable:

save(mat_'string', file="mat.Rdata")

The question is how to pass the new variable name in the save argument.

4

1 に答える 1

7

のドキュメントは、逆引きを行うassignために使用することを提案しています (最後の例を参照してください)。get

> a = 1
> get('a')
[1] 1

で使用するにはsave

to_be_saved_obj = paste("mat", a, sep = "_")
save(list = to_be_saved_obj, file = 'mat.Rdata')
于 2013-08-30T11:10:57.960 に答える