0

I am workign with NLS data and try to recode the gender variable, where I called it female from the beginning and now I try to recode the following

 1 Male
 2 Female
 0 No Information

My code:

nlsy$female[ nlsy$female == 1 ] <- 0
nlsy$female[ nlsy$female == 2 ] <- 1

However, I get the following error from R:

Error in `$<-.data.frame`(`*tmp*`, "female", value = numeric(0)) :    replacement has 0 rows, data has 7120

Any suggestions?

divibisan
  • 11,659
  • 11
  • 40
  • 58
bree
  • 25
  • 1
  • 7
  • Please show a small example using `dput`. According to the data you showed, the syntax should work – akrun Apr 23 '17 at 05:22
  • 1
    Did the solution wind up being that the value was 'Female' (capital 'F') and you were trying to access 'female' (lower case 'f')? That seems to be what your comment on the answer implies. – Conspicuous Compiler Mar 14 '19 at 20:28

1 Answers1

1

what I would check:

  1. data.frame nlsy is not empty, by empty i mean with 0 rows / records.
  2. do you have a column named 'female' in the data.frame nlsy
  3. class of the column, is it integer or character or others
  4. after all the checks

    nlsy$female[which(nlsy$female == 2)] <- 1

sinalpha
  • 383
  • 1
  • 9
  • 1
    Switching from SAS to R I sometimes forget that R is case sensitive. Thanks a lot! – bree Apr 23 '17 at 22:58