[R] Using object as literal value in list vector
LCOG1
jroll at lcog.org
Wed Jun 20 02:31:44 CEST 2012
Hello all ,
This is a pretty simple question I think but cannot find an answer on the
list or in my brain. I would like to iterate through a loop and use a
vector of strings to name a number of list elements. For instance
#Create vector of strings
Et<- c("ACC","RTL","WHL")
MeanValues_ <- list("ACC" = 1000, "RTL" = 2000, "WHL" = 3000)
#Iterate through each element of vector
NewMeans_ <- list()
for(et in Et){
NewMeans_ <- c(NewMeans_,list(et = unlist(MeanValues_[et]) * .80 ))
}
Returns
> NewMeans_
$et
ACC
800
$et
RTL
1600
$et
WHL
2400
But I want 'et' to be the object value of et, so it would be $ACC, $RTL, and
$WHL. I realize there may be another way to actually do what I want to do
as far as applying the calculation but I have a bunch of code structured
around the need for my list coming in a certain way. Thanks
Josh
--
View this message in context: http://r.789695.n4.nabble.com/Using-object-as-literal-value-in-list-vector-tp4633912.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list