1

I am running through loop and I want to select columns 1,i,j

When I run it with 1 i j I get this result:

> trainingSet[,c(1,i,j)]
[1] 1 2 3

When i run it for example with 1 2 3 I got this result that expected:

> trainingSet[,c(1,2,3)]
     Class Alcohol Malic_acid
  1:     1   14.23       1.71
  2:     1   13.20       1.78
  3:     1   13.16       2.36
  4:     1   14.37       1.95
  5:     1   13.24       2.59
 ---                         
122:     3   14.16       2.51
123:     3   13.71       5.65
124:     3   13.27       4.28
125:     3   13.17       2.59
126:     3   14.13       4.10

How i can fix this?

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Zakk
  • 758
  • 3
  • 11
  • 20
  • This is because of the new feature in `data.table` which allows you to select columns by locations just like in a `data.frame` up until you pass an expression to the `j`th location. See [bullet #3](https://github.com/Rdatatable/data.table/blob/master/NEWS.md#changes-in-v198--on-cran-25-nov-2016). Your specific case is solvable using `trainingSet[, c(1, i, j), with = FALSE]` – David Arenburg Jan 29 '17 at 11:47
  • Fixed :) Write reply so I can finish. Thanks alot – Zakk Jan 29 '17 at 11:50

0 Answers0