0

In R, I want to use a subset of a dataframe 'RL', by selecting specific headers (eg. 'RL$age01' etc.. I generate the selected headers as a vector of strigs:

v = c('ID', sprintf("sex%02d", seq(1,15)), sprintf("age%02d", seq(1,15)))

and the dataframe index as:

c = sprintf('RL$%s', v)

how can I evaluate these strigns to call the dataframe columns by header and rearange them in a matrix, in the sense of x = cbind(RL$ID, RL$age01, ...) ? cbind(c) does not work neither using things like eval(), parse() or expression().

Thanks for any help

Rafael

Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184
rlue
  • 3
  • 2
  • 2
    You can['t do that with `$` - see http://stackoverflow.com/a/18228613/1478381 for more info. Use e.g. `RL[ , 'age01' ]` for your column name, or just `RL[ , v ] ` will work given your data above. – Simon O'Hanlon Nov 04 '13 at 13:48

1 Answers1

1

Just use

RL[,v]

Just noticed this was already mentioned in the comments.

Rohit Das
  • 1,962
  • 3
  • 14
  • 23