0

i have a list of team names (teamNames) and a list of data frames (weekSummaries)

i want to get a list of team summaries by week:

teamSummaries <- llply(teamNames,getTeamSubset)

getTeamSubset = function(teamName){
  temp=ldply(weekSummaries,subset,team_name==teamName)
}

however, when i run this i get an error

>Error in eval(expr, envir, enclos) : object 'teamName' not found

but when i run the command

>ldply(weekSummaries,subset,team_name=="Denver Broncos")

i get a data frame with the information i need for one team... can somebody point out what i'm doing wrong?

Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
dance
  • 337
  • 4
  • 8
  • 2
    See http://adv-r.had.co.nz/Computing-on-the-language.html and http://stackoverflow.com/questions/9860090/in-r-why-is-better-than-subset. – mnel Dec 17 '13 at 22:48
  • thanks @mnel. from looking at those links, it looks like subset works within the scope of the data_frame it is passed. i couldn't seem to sort out how to fix it with eval. i'm posting an alternate solution that uses a custom function, thus avoiding subset altogether. – dance Dec 18 '13 at 02:14

1 Answers1

0

Looks like the answer is not to use the subset function, and instead to use a custom function, passing it the data frame, then subsetting using bracket notation. such as this:

teamSummaries <- llply(teamNames,getTeamSubset)

getTeamSubset = function(teamName){
  temp=ldply(weekSummaries,function(week){
    week[week$team_name==teamName,]
  })
}
dance
  • 337
  • 4
  • 8