1

Coming from Stata this seems to be an easy thing, though I cannot find a solution with R, though I read How to read a subset of large dataset in R?

Is it possible as it is in Stata to name the variables from a dataset I need and load just them? Is it then possible to name again specific variables from another data set and merge them?

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
Stephan
  • 113
  • 14
  • check out `data.table::fread`, which has arguments `select` and `drop` – bouncyball Jun 29 '16 at 15:50
  • I don't think `read.dta` from the foreign package (Stata 12-) or `read.dta13` from readstata13 (Stata 13-14) have this option. Your best bet would be reading the .dta file once, saving it as an R binary, with `save` or subsetting and then saving. – lmo Jun 29 '16 at 15:51
  • @bouncyball I haven't tried it, but I don't think `fread` will read in .dta files. – lmo Jun 29 '16 at 16:00
  • @Imo I don't think so either, but in case OP converted their .dta to a more friendly format – bouncyball Jun 29 '16 at 16:09
  • Hm so I guess there is no other way than to change the format. However thank you! – Stephan Jun 30 '16 at 09:38

1 Answers1

3

I haven't tested it myself, but the latest version of the readstata13 package seems to allow for subsetting on both columns and rows:

read.dta13(file, convert.factors = TRUE, 
           generate.factors = FALSE, encoding = "UTF-8", 
           fromEncoding = NULL, convert.underscore = FALSE, 
           missing.type = FALSE, convert.dates = TRUE, 
           replace.strl = TRUE, add.rownames = FALSE, 
           nonint.factors = FALSE, select.rows = NULL, 
           select.cols = NULL, strlexport = FALSE, 
           strlpath = ".")
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
atmo
  • 66
  • 1
  • 6