0

I have a dataset with about 2,384 variables but only need to use about 39 of them. I have tried to remove the columns that I am working with into another dataset but I keep getting undefined columns selected error message. Below is the code I wrote:

BR <- BR[, c("id","today_m0","miscarriedwk","p1_status","p2_status","p_status", "p3_status","preg_bl","preg_m6","preg_m12","preg_m18","secedu","married","numchild","numpregnancies","nummiscarriages","numdeliveries","pHIV_bsln","chart_cd4_m0","j8_m0","partnernowsHIV_m0","partnertakesHIV_m0","depression_m0","meanhivstigma_m0","meanpersonalstigma_m0","female_m0","CommstigmaFinal_m0","j12r_m0","PMTCT","ANC","j10_m0","age_m0","intention1year")]

  • 2
    "Undefined columns" means no column with that name, so probably a typo in there somewhere. – neilfws Jun 01 '17 at 01:37
  • R is case sensitive, please check if there are any names with characters that are not aligning with the original. – akrun Jun 01 '17 at 04:02

1 Answers1

0

The dplyr package is a great tool for cleaning up data:

library(dplyr)
select(BR, id, today_m0, miscarriedwk, p1_status, # etc

The beauty of using this approach is that the error message will tell you which of your column names are wrong:

> select(BR, junk)
Error in eval(expr, envir, enclos) : object 'junk' not found
lebelinoz
  • 4,890
  • 10
  • 33
  • 56