[R] rep() inside of lm()?
iliketurtles
isaacm200 at gmail.com
Sun Jan 1 15:13:46 CET 2012
HI all,
I'm new to R.
Say I have a multi-layered list called newlist.
############
> str(newlist)
List of 2
$ :List of 5
..$ : num [1:8088] NA 464 482 535 557 ...
..$ : num [1:8088, 1:2] NA 464 482 535 557 ...
..$ : num [1:8088, 1:3] NA 464 482 535 557 ...
..$ : num [1:8088, 1:4] NA 464 482 535 557 ...
..$ : num [1:8088, 1:5] NA 464 482 535 557 ...
$ :List of 3
..$ : num [1:8088] NA NA 1386 464 482 ...
..$ : num [1:8088] NA NA NA 1386 464 ...
..$ : num [1:8088] NA NA NA NA 1386 ...
############
Let's say this list has 2 entries. i.e. length(newlist)=2. However, in my
function this list can be any number of entries, 1 to N. I want to regress
each newlist[[N]] in a multiple linear regression. The problem is I don't
know how to make a non-character or a non-numeric repeat.
So I'd want something like:
#---------------------------
dumplist<-list()
for(a in 1:length(newlist[[1]])){
for(b in 1:length(newlist[[2]]){
for(terminal in 1:length(newlist[[length(newlist)]])){
dumlist[[..]]<-lm(y~newlist[[1]][a] + newlist[[2]]][b] + ....... +
newlist[[N]][terminal]).
}}}
#---------------------------
and I want the above to adjust to whatever N is.
I'm new to R so this kind of thing is very difficult. I'm experimenting with
eval(), parse(), paste(), expression(), letters[] and other stuff but I'm
not getting far and I would greatly appreciation any guidance.
Thank you.
-----
----
Isaac
Research Assistant
Quantitative Finance Faculty, UTS
--
View this message in context: http://r.789695.n4.nabble.com/rep-inside-of-lm-tp4250712p4250712.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list