Q: Subsetting Last N Values From a Data Frame, R I have a data frame of all the results of a football season, in a data frame called new. I want to extract the last 5 games of all teams home and away. The home variable is column 1 and away variable is column 2.
Say there are 20 teams in a character vector called teams, each with a unique name. If it was just a single team it would be easy to subset - say if team1 was "Arsenal", using something like 
 Arsenal <- "Arsenal"
 head(new[new[,1] == Arsenal | new[,2] == Arsenal,], 5)

But I want to loop through the character vector teams to obtain the last 5 results of all teams, 20 in total. Can somebody help me please? 
Edit: Here is some sample data. As an example, I would like to obtain the last two games of all teams- it would be easy to subset a single team but I'm not sure how to subset multiple teams. 
             V1          V2 V3 V4         V5
1       Chelsea     Everton  2  1 19/05/2013
2     Liverpool         QPR  1  0 19/05/2013
3      Man City     Norwich  2  3 19/05/2013
4     Newcastle     Arsenal  0  1 19/05/2013
5   Southampton       Stoke  1  1 19/05/2013
6       Swansea      Fulham  0  3 19/05/2013
7     Tottenham  Sunderland  1  0 19/05/2013
8     West Brom  Man United  5  5 19/05/2013
9      West Ham     Reading  4  2 19/05/2013
10        Wigan Aston Villa  2  2 19/05/2013
11      Arsenal       Wigan  4  1 14/05/2013
12      Reading    Man City  0  2 14/05/2013
13      Everton    West Ham  2  0 12/05/2013
14       Fulham   Liverpool  1  3 12/05/2013
15   Man United     Swansea  2  1 12/05/2013
16      Norwich   West Brom  4  0 12/05/2013
17          QPR   Newcastle  1  2 12/05/2013
18        Stoke   Tottenham  1  2 12/05/2013
19   Sunderland Southampton  1  1 12/05/2013
20  Aston Villa     Chelsea  1  2 11/05/2013
21      Chelsea   Tottenham  2  2 08/05/2013
22     Man City   West Brom  1  0 07/05/2013
23        Wigan     Swansea  2  3 07/05/2013
24   Sunderland       Stoke  1  1 06/05/2013
25    Liverpool     Everton  0  0 05/05/2013
26   Man United     Chelsea  0  1 05/05/2013
27       Fulham     Reading  2  4 04/05/2013
28      Norwich Aston Villa  1  2 04/05/2013
29          QPR     Arsenal  0  1 04/05/2013
30      Swansea    Man City  0  0 04/05/2013
31    Tottenham Southampton  1  0 04/05/2013
32    West Brom       Wigan  2  3 04/05/2013
33     West Ham   Newcastle  0  0 04/05/2013
34  Aston Villa  Sunderland  6  1 29/04/2013
35      Arsenal  Man United  1  1 28/04/2013
36      Chelsea     Swansea  2  0 28/04/2013
37      Reading         QPR  0  0 28/04/2013
38      Everton      Fulham  1  0 27/04/2013
39     Man City    West Ham  2  1 27/04/2013
40    Newcastle   Liverpool  0  6 27/04/2013
41  Southampton   West Brom  0  3 27/04/2013
42        Stoke     Norwich  1  0 27/04/2013
43        Wigan   Tottenham  2  2 27/04/2013


A: take a look at sapply
sapply(unique(new[,1]), function(team) head(new[new[,1] == team | new[,2] == team,], 5))


A: Where df is  your data.frame, this will create a list of 20 data.frames with each element being the dataset for one team. This also assumes that the dataset is already ordered, since you mentioned it.
 setnames(df,c('hometeam','awayteam','homegoals','awaygoals','fixturedate'))

 allteams <- sort(unique(df$hometeam))

 eachteamlastfive <- vector(mode = "list", length = length(allteams))

 for ( i in seq(length(allteams)))
 {
 eachteamlastfive[[i]] <- head(df[df$hometeam==allteams[i] | df$awayteam == allteams[i], ],5)
 }

