If I have several character vectors, for example:
a_c('data.')
b_c('_myfunction(')
c_c('vect.')
d_c(')')
and, j_1
I can build a vector using paste:
x_paste(a,j,b,c,j,d,sep="")
x="data.1_myfunction(vect.1)"
I have n numeric vectors (vect.1...vect.n)
Then, if I could evaluate the string x, I would calculate the
result of my function in n-vectors using a loop
for (j in 1:n){
x_paste(a,j,b,c,j,d,sep="")
function.to.evaluate.string(x)
}
As a result, I would have n data.j objects
I've been looking for a function in R to evaluate a string
and I haven't found anyone.
Is there any function to do that?
Thank you very much
--
=============================================================Alvaro Colina
|-|o||o||o||o||o||o||o||o||o|-
Area de Quimica Analitica | Pza. Misael Banuelos s/n
Facultad de Ciencias | 09001. Burgos. Spain
Universidad de Burgos | Phone: 34-947-258817
e-mail: acosa at ubu.es | FAX: 34-947-258831
=============================================================-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Alvaro Colina <acosa at ubu.es> writes:> x_paste(a,j,b,c,j,d,sep="") > > x="data.1_myfunction(vect.1)" > > I have n numeric vectors (vect.1...vect.n) > Then, if I could evaluate the string x, I would calculate the > result of my function in n-vectors using a loop > for (j in 1:n){ > x_paste(a,j,b,c,j,d,sep="") > function.to.evaluate.string(x) > } > As a result, I would have n data.j objects > > I've been looking for a function in R to evaluate a string > and I haven't found anyone. > > Is there any function to do that?parse() followed by eval(), but it's generally a bad idea. for(j in 1:n){ v<-paste("vect.",j,sep="") d<-paste("data.",j,sep="") assign(d,myfunction(get(v))) } -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._