[R] accessing an object with a variable ?

ce zadig_1 at excite.com
Sat Jan 18 22:21:33 CET 2014


I want access and object , its name is in an variable :

require(xts)
data(sample_matrix)

head(sample_matrix)
               Open     High      Low    Close
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
2007-01-04 50.42096 50.42096 50.26414 50.33236
2007-01-05 50.37347 50.37347 50.22103 50.33459
2007-01-06 50.24433 50.24433 50.11121 50.18112
2007-01-07 50.13211 50.21561 49.99185 49.99185
> assign("a",sample_matrix)
> head(a)

               Open     High      Low    Close
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
2007-01-04 50.42096 50.42096 50.26414 50.33236
2007-01-05 50.37347 50.37347 50.22103 50.33459
2007-01-06 50.24433 50.24433 50.11121 50.18112
2007-01-07 50.13211 50.21561 49.99185 49.99185


But following doesn't work:

b="sample_matrix"
assign("a",b)

> a
[1] "sample_matrix"

how I can access sample_matrix data when I have only b variable ?



More information about the R-help mailing list