Help with Nesting

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with Nesting

R help mailing list-2
How do i resolve this?

symbol <-  c('RRR' ,'GGG')

for(i in seq_along(symbol)) {
  dat <- Quandl("LLL/symbol[i]")
 
}
 
required solutionis a loop where Quandl is a function and it loops as flows,
Quandl("LLL/RRR")
Quandl("LLL/GGG")

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with Nesting

Rui Barradas
Hello,

This is cross-posted from

https://stackoverflow.com/questions/47042591/how-to-resolve-nested-variables-inside-a-loop-in-r

And you already have the answer there. See my comment.

Rui Barradas

Em 31-10-2017 19:00, Edward Guda via R-help escreveu:

> How do i resolve this?
>
> symbol <-  c('RRR' ,'GGG')
>
> for(i in seq_along(symbol)) {
>    dat <- Quandl("LLL/symbol[i]")
>
> }
>
> required solutionis a loop where Quandl is a function and it loops as flows,
> Quandl("LLL/RRR")
> Quandl("LLL/GGG")
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with Nesting

Jeff Newmiller
In reply to this post by R help mailing list-2
R does not look inside strings for language objects like your symbol variable. Nor does it magically figure out that it needs to keep previous values in a loop. And you need to be able to use valid syntax to ask clear questions in this list, so some more time with a tutorial should occur before you post again.

Perhaps:

result <- lapply( symbol, function(s) {
   Quandl( paste0( "LLL/", s ) )
}
result
--
Sent from my phone. Please excuse my brevity.

On October 31, 2017 12:00:41 PM PDT, Edward Guda via R-help <[hidden email]> wrote:

>How do i resolve this?
>
>symbol <-  c('RRR' ,'GGG')
>
>for(i in seq_along(symbol)) {
>  dat <- Quandl("LLL/symbol[i]")
>  
>}
>
>required solutionis a loop where Quandl is a function and it loops as
>flows,
>Quandl("LLL/RRR")
>Quandl("LLL/GGG")
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.