[R] Accessing a list

David Winsemius dwinsemius at comcast.net
Thu Apr 26 01:31:26 CEST 2012


On Apr 25, 2012, at 6:02 PM, Greg Snow wrote:

> I believe that fortune(312) applies here.  As my current version of
> fortunes does not show this I am guessing that it is in the
> development version and so here is what fortune(312) will eventually
> print (unless something changes or I got something wrong):
>
> The problem here is that the $ notation is a magical shortcut and like
> any other magic if used incorrectly is likely to do the programmatic  
> equivalent of turning
> yourself into a toad.
> —Greg Snow (in response to a user that wanted to access a column  
> whose name is
> stored in y via x$y rather than x[[y]])
> R-help (February 2012)

I second this self-numeration, ...  errr,  self-nomination. I thought  
it was by the maintainer of the mind reading machine, but I see on  
investigation that was Dirk E. I see that 291 is the highest current  
fortune but ... hey ... what the heck ... why not have some NULL  
fortunes hanging around?

-- 
David
>
> On Tue, Apr 24, 2012 at 9:42 PM, Jim Silverton <jim.silverton at gmail.com 
> > wrote:
>> Hi,
>> I have the following problem- I want to access a list whose  
>> elements are
>> imp1, imp2, imp3 etc I tried theusing the paste comand in a for  
>> loop see
>> the last for loop below. But I keep calling it df but df = imp1  
>> (for the
>> first run). Any ideas on how I can access the elements of the list?
>>
>> Isaac
>>
>>
>>
>> require(Amelia)
>> library(Amelia)
>> data.use <- read.csv("multiplecarol.CSV", header=T)
>> names(data.use) = c("year", "dischargex1", "y", "pressurex2" ,  
>> "windx3")
>>
>> ts <- c (c(1:12), c(1:12), c(1:12), c(1:12), c(1:12), c(1:12),  
>> c(1:12),
>> c(1:6) )
>> length(ts)
>> data.use = cbind(ts, data.use)
>>
>> #a.out2 <- amelia(data.use, m = 1000, idvars = "year")
>>
>>
>> n.times = 100
>> a.out.time <- amelia(data.use, m = n.times, ts="ts", idvars="year",
>> polytime=2)
>>
>> constant.col = dischargex1.col = pressurex2.col = windx3.col =
>> rep(0,n.times)
>>
>> for (i in 1: n.times)
>> {
>> x = c("imp",i)
>> df = paste(x, collapse = "")
>> data1 = a.out.time[[1]]$df
>> attach(data1)
>> y = as.numeric(y)
>> dischargex1 = as.numeric(dischargex1)
>> pressurex2 = as.numeric(pressurex2)
>> windx3 = as.numeric(windx3)
>> multi.regress = lm(y~ dischargex1 + pressurex2 + windx3)
>> constant.col[i] = as.numeric(multi.regress[[1]][1])
>> dischargex1.col[i] = as.numeric(multi.regress[[1]][2])
>> pressurex2.col[i] = as.numeric(multi.regress[[1]][3])
>> windx3.col[i] = as.numeric(multi.regress[[1]][4])
>> }
>>
>>
>> --
>> Thanks,
>> Jim.
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> -- 
> Gregory (Greg) L. Snow Ph.D.
> 538280 at gmail.com
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list