-1

So I have a data frame that expresses the relationship between year, wages, degree, gender, and age. For the year, there are 2015 and 1996. How do I create a new variable that only expressed the income belongs to the year 2015?

Please help me, I am devastated right now

Dataset looks like

vitas
  • 1
  • Please provide us with a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so that we can help you in the best possible way. – lovalery Oct 13 '21 at 21:49
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 15 '21 at 08:08

1 Answers1

0

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
cgvoller
  • 873
  • 1
  • 14