title: R : Caret how do we pass a parameter for k for kNN
body: <p>I am using caret for knn and I initially run the process with tuneLength=10
  I found that the one used for the model have k=21</p>
  
  <p>I would like to run the parameter with a specific set of k values and I am encountering errors passing the values in the tuneGrid or pass k values directly to the train function </p>
  
  <p>Data:</p>
  
  <pre><code>library(mlbench)
  data(PimaIndiansDiabetes)
  </code></pre>
  
  <p>Code: </p>
  
  <pre><code>grid = expand.grid(k = c(5,7,9,15,19,21)
  
  compute_learncurve5 &lt;- function(df=adultFile,control=control,ratio=30,fold=10,N=3,metric="Accuracy",
                                  seed=1234,scaled=FALSE,DEBUG=FALSE) {
    result_df = c()
    size &lt;- round(size=(ratio/100 * nrow(df)))
    split &lt;-  gsub(" ","",paste(as.character(100-ratio),"/",as.character(ratio)))
    iter &lt;-  N
    trainSize &lt;-  nrow(df)-size
    testSize &lt;-  size
  
    if (DEBUG){
      print(paste("Dimension of InputDataSet : ", dim(df)))
      print(paste("Test/Train Perct : ",ratio,"|",100-ratio,
                  " : Train/Test size = ", trainSize,"|",testSize))
    }
  
    #Set-up data
    trainpct  &lt;- (100-ratio)/100
  
    # Set-up Train and Test - Change target variable
    inDfTraining &lt;- createDataPartition(df$response, p = trainpct, list = FALSE)
    inTraining &lt;- df[ inDfTraining,]
    inTesting  &lt;- df[-inDfTraining,]
  
    # Run algo to generate MODEL
    set.seed(seed)
    metric=metric
    control=control
    grid = expand.grid(k. = c(5,7,10,15,19,21))
  
    Fit.kNN &lt;- train(response~., data=df, method="knn", metric=metric, preProc=preProc, trControl=control,
                     tuneGrid=grid)
  
  
  }
  
  learnCurve_df5 = c()
  for (i in seq(95, 5, -5)) {
    learnCurve_df5 &lt;- rbind(learnCurve_df5,compute_learncurve5(df=adultFile))
  }
  </code></pre>