[R] Using loops to create matrices where the variables is called with $

Rui Barradas ruipbarradas at sapo.pt
Mon Jul 9 10:19:43 CEST 2012


Hello,

I'm not completely sure I understand your problem, you should say what 
is the package you are using.

If it's just a doubt on how to access the elements of what seems to be a 
list, here is an example:

x <- list(a=1:5, b=rnorm(4))

x$a
x[[ "a" ]]
x[[ 1 ]]

If it's from package vars, the help page says the return value is a 
"list with matrices", and then you can easily adapt the example above.

In which case I'd recommend you take a look at An Introduction to R, 
file R-intro.pdf in the doc folder/directory of your R installation:

"Chapter 6: Lists and data frames

Components are always numbered and may always be referred to as such. [...]
in the simple example given above:
Lst$name is the same as Lst[[1]]"

As you can see, it would have saved you some time.

Hope this helps,

Rui Barradas

Em 09-07-2012 02:03, Drew Harris escreveu:
> Hi there,
>
> I am trying to make a VECM model which does a loop to pull of long run
> impact coefficients. The problem is that to calculate these for a,b,c I use
> the irf() function and they are stored in irf$a, irf$b, irf$c. What I would
> really like is to be able to call irf$[variablename(x)] where I can loop
> through i:n for x and it will pull out the right variable. This is a bit of
> a waste of time for 3 but I want it to do bigger sets and sets of different
> lengths so I don;t have to keep recoding it.
>
> Any advice would be much appreciated,
>
> Cheers,
>
> Drew
>
> 	[[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.
>



More information about the R-help mailing list