2

I have a variable a=0.01

Then I create a matrix: b<-matrix(data=1:5,ncol=5,nrow=1)

I would now like to save the matrix so that the name of the matrix is the value stored in a:

save(b_'string', file="b_'string'.Rdata")

Where 'string' should be the value stored in a, i.e. 0.01

So the file should be called b_0.01.Rdata and the variable stored should be b_0.01

2
  • 2
    save(b,file=paste0("b_",a,".Rdata")) Commented Aug 30, 2013 at 10:18
  • but how about adding 0.01 to the variable name within the file? Commented Aug 30, 2013 at 10:25

1 Answer 1

2

You need to create a new string to feed to file, e.g. using paste0:

save(b,file=paste0("b_",a,".Rdata"))
Sign up to request clarification or add additional context in comments.

1 Comment

You should probably either save 'a' as well to the file, or add 'a' as an attribute to matrix 'b' so you know what it meant.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.