Hi Serban and Everyone,
If I follow correctly, you might want code that takes a vector of names
and then uses it to add prefixes to existing variables. It might go like
this:
###the names of the countries
vector1 <- c("russia","estonia","latvia")
###dataset with variables
dta <- cbind(rnorm(100),rnorm(100),rnorm(100))
###initialize vector
txt <- c()
###loop over elements in text vector that are part of name
for(i in 1:length(vector1)){
txt <- c(txt,paste(vector1[i],".growth",sep=""))
}
colnames(dta) <- txt
Clearly, this could be expanded using some similar strategy to create not
just "russia.growth" but "russia.income" etc. by using the for loop
properly.
Best,
Dan
----
Ph.D. Student
Department of Government
Harvard University
Tutor, Currier House
dhopkins(a)fas.harvard.edu
http://www.danhopkins.org
On Tue, 4 Apr 2006, Serban Tanasa wrote:
Hello!
I was wondering, does anyone know whether it is possible to create
variables dinamically, and also name and use them dinamically too? Say i
have a list like c("Sicilia","Russia","Mafialand"), and I
want to create
a variable that has a human-comprehensible name, like the first few
letters from a list of country names.
would it be possible to dinamically create variables with names that
reflect the character strings, like "Russia.growth"? I am asking for
automation's sake, as I am tired of having to set ylab and xlab if i can
help it.
Thanks,
--
Serban Tanasa
Email: tanasa(a)fas.harvard.edu
Cell: 617-833-7847
Address: 513 Cabot Mail Center, Cambridge, MA 02138