Using the wage data and dplyr
, this will create a new column called New and give a wage value for the year 2006.
Wage %>% mutate(New = ifelse(year==2006,wage,NA))
Output:
year age maritl race education region jobclass health health_ins logwage wage New
2006 18 1. Never Married 1. White 1. < HS Grad 2. Middle Atlantic 1. Industrial 1. <=Good 2. No 4.318063 75.04315 75.04315
2004 24 1. Never Married 1. White 4. College Grad 2. Middle Atlantic 2. Information 2. >=Very Good 2. No 4.255273 70.47602 NA
2003 45 2. Married 1. White 3. Some College 2. Middle Atlantic 1. Industrial 1. <=Good 1. Yes 4.875061 130.98218 NA
2003 43 2. Married 3. Asian 4. College Grad 2. Middle Atlantic 2. Information 2. >=Very Good 1. Yes 5.041393 154.68529 NA
2005 50 4. Divorced 1. White 2. HS Grad 2. Middle Atlantic 2. Information 1. <=Good 1. Yes 4.318063 75.04315 NA
2008 54 2. Married 1. White 4. College Grad 2. Middle Atlantic 2. Information 2. >=Very Good 1. Yes 4.845098 127.11574 NA
2009 44 2. Married 4. Other 3. Some College 2. Middle Atlantic 1. Industrial 2. >=Very Good 1. Yes 5.133021 169.52854 NA
2008 30 1. Never Married 3. Asian 3. Some College 2. Middle Atlantic 2. Information 1. <=Good 1. Yes 4.716003 111.72085 NA
2006 41 1. Never Married 2. Black 3. Some College 2. Middle Atlantic 2. Information 2. >=Very Good 1. Yes 4.778151 118.88436 118.88436