[R] scanning a data set for strings

R. Michael Weylandt michael.weylandt at gmail.com
Wed May 2 15:55:19 CEST 2012


I think you are looking for something like

aggregate(cbind(VPts, HPts) ~ VTm + HTm, data = NFL, sum)

but you should look at the examples for ?aggregate to tweak it to what
you need.

Michael

On Wed, May 2, 2012 at 7:45 AM, Daniel_55 <serna.danny at gmail.com> wrote:
> Hello,
>
> I'm looking for what I'm sure is a quick answer. I'm working with a data set
> that looks like this:
>
>  Week              Game.ID                     VTm VPts HTm HPts
> Differential HomeWin
> 1    1  NFL_20050908_OAK at NE   OAK   20      NE     30           10
> FALSE
> 2    1 NFL_20050911_ARI at NYG    ARI   19      NYG   42           23
> FALSE
> 3    1 NFL_20050911_CHI at WAS   CHI    7       WAS    9            2
> FALSE
> 4    1 NFL_20050911_CIN at CLE    CIN   27       CLE    13          -14
> FALSE
> 5    1  NFL_20050911_DAL at SD     DAL   28      SD      24           -4
> FALSE
> 6    1 NFL_20050911_DEN at MIA  DEN   10     MIA    34           24
> FALSE
>
> NFL data. I want to pair each team with the points they received at home and
> away and create another table showing this. I know it's easy to do, but all
> the methods I am coming up with involve doing each team individually via a
> for loop that searches for [i,5]=="NE", [i,5]=="NYG". I would then use the
> same method to pair the same team code ("NYG" or "NE") with VPTs when it's
> Visiting.
>
> Thanks for the help.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/scanning-a-data-set-for-strings-tp4602953.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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