[R] Help pasting string as object name

Rob Denniker bearmarketsrule at inbox.com
Fri Apr 3 11:40:36 CEST 2009


I have a data frame containing monthly observations of the 'density' of each US state, recorded in variables named "density.AL", "density.AK", "density.AZ", and so on for all 50 states. The data frame (called d) also contains a variable called "Date" which is encoded as a string in the format "Jan-09", "Feb-09", etc.

I also have a vector st.list<-c("AL", "AK", "AZ",...) of length 50.

I would like a new dataframe with st.list in one column and the value of "d$density" for that state when d$Date==Feb-09 in another column.

How can I do this?

Here is what I have tried:

names <- rep("d$density",length(st.list))
templist <- as.vector(mapply(paste, names, st.list ,sep="."))

d.2<-data.frame()
for (i in 1:length(templist)) {
d.2$density[i] <- subset(parse(file="",templist[i]),d$Date=="Feb-09")
i<-i+1 }   ### hangs!


Thanks for any help!

____________________________________________________________
GET FREE 5GB EMAIL - Check out spam free email with many cool features!
Visit http://www.inbox.com/email to find out more!




More information about the R-help mailing list