I have a listing of New York Mets baseball players from the Lahman
database in alphabetical order. For each player are the years he played in ascending order. I need to extract for each player just the data for the first year he played and put all the first rows into a new data frame.
On my Mac in RStudio
I have gotten to the point where the data I need is grouped and ordered. Here is a sample.
playerID,yearID,G,AB,R,H
aceveju01,1997,25,6,0,0
acostma01,2010,41,0,0,0
acostma01,2011,44,0,0,0
acostma01,2012,45,0,0,0
adkinjo01,2007,1,0,0,0
agbaybe01,1998,11,15,1,2
agbaybe01,1999,101,276,42,79
agbaybe01,2000,119,350,59,101
agbaybe01,2001,91,296,28,82
ageeto01,1968,132,368,30,80
ageeto01,1969,149,565,97,153
ageeto01,1970,153,636,107,182
ageeto01,1971,113,425,58,121
ageeto01,1972,114,422,52,96
aguilch01,2008,8,12,0,2
For testing purposes, I started with this code instead of with piping
. That is as far as I was able to advance.
Lahman_batting18 <- read.csv('Batting-copy.csv', header = TRUE, stringsAsFactors=FALSE)
Lahman_batting18s <- select(Lahman_batting18,playerID:SO)
Lahman_batting18f <- filter(Lahman_batting18s,teamID == 'NYN')
Lahman_batting18fa <- arrange(Lahman_batting18f, playerID, yearID)
Desired output:
playerID,yearID,G,AB,R,H
aceveju01,1997,25,6,0,0
acostma01,2010,41,0,0,0
adkinjo01,2007,1,0,0,0
agbaybe01,1998,11,15,1,2
ageeto01,1968,132,368,30,80
aguilch01,2008,8,12,0,2
Thanks for your help!