r - Work With a Value in a Data Frame by Character -


i have data frame column of text formatted nba season such:

year 2014-15 2013-14 2012-13 ... 1999-00 

i need reformat second year. small data set, , don't mind manually fixing 1999-00 value, can't figure out how to:

paste(data$year[1:2],data$year[6:7]) 

to get:

year 2015 2014 2013 ... 2000 

i think simplest extract first year , add one:

as.numeric(substr(data$year, 1, 4)) + 1 # [1] 2003 2002 2001 2000 1999 

data:

(data <- data.frame(year=c("2002-03", "2001-02", "2000-01", "1999-00", "1998-99"))) #      year # 1 2002-03 # 2 2001-02 # 3 2000-01 # 4 1999-00 # 5 1998-99 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -