Sunny Singha
2016-Mar-10 07:56 UTC
[R] Help -- feed data frames, returned from function into list --
Hi, I got a problem. Using loop, I'm trying to feed data frames, returned from the function, into the list but not all data frames are getting captured. I have vector with some string values which I want to pass to the function. *groups* <- c('cocacola', 'youtube','facebook) for(i in 1:length(groups)){ g <- list() g[[i]] <- searchGroups_mod(*groups[i]*, token=fb_oauth, 10) } The result list stores data frame only for the last string in the 'groups' vector. Why the List is getting reassigned for each iteration ? Please guide. Regards, Sunny Singha. [[alternative HTML version deleted]]
Berend Hasselman
2016-Mar-10 08:27 UTC
[R] Help -- feed data frames, returned from function into list --
> On 10 Mar 2016, at 08:56, Sunny Singha <sunnysingha.analytics at gmail.com> wrote: > > Hi, > I got a problem. Using loop, I'm trying to feed data frames, returned from > the function, into the list but not all data frames are getting captured. > > I have vector with some string values which I want to pass to the function. > > *groups* <- c('cocacola', 'youtube','facebook) >You posted in HTML. In a plain text mailing list we see *groups* which is nonsense. You boldified? Please do not do that and do not post in HTML.> for(i in 1:length(groups)){ > g <- list() > g[[i]] <- searchGroups_mod(*groups[i]*, token=fb_oauth, 10) > } > > The result list stores data frame only for the last string in the 'groups' > vector. > Why the List is getting reassigned for each iteration ? Please guide. >Because you are creating the list g inside the loop. Put the g <- list) before the loop.> Regards, > Sunny Singha. > > [[alternative HTML version deleted]]__This is a plain text mailinglist. Do not post in HTML. Berend> ____________________________________________ > R-help at r-project.org 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.