1

I want to use column index in dcast in data.table:

dcast(setDT(x),rowid(X__9) ~ X__9,value.var = "count")

Above works fine,but column name X__9 is dynamic it may change to X__7 or X__8. How can we pass column index 1 to dcast so that every time it will work irrespective of dynamic column names. I tried:

dcast(setDT(x),rowid(names(.)[1]) ~ names(.)[1],value.var = "count")

But it does not work.

Jaap
  • 81,064
  • 34
  • 182
  • 193
Neil
  • 7,937
  • 22
  • 87
  • 145

0 Answers0