Why does the first line work but the second line does not? 


  # This does not work
  DT[, min(which(DT[,group, with=FALSE]==G)), by=list(G=Season)   ]

  # This does work
  DT[, min(which(DT[,group, with=FALSE]==as.character(G))), by=list(G=Season)   ]

  # This also works
  DT[, min(which(DT[,get(group)]==G)), by=list(G=Season)   ]
  
  # If we convert the whole column to character (rather, away from factor)
  #   then the original line works. 
  DT[, Season := as.character(Season)]
  DT[, min(which(DT[,group, with=FALSE]==G)), by=list(G=Season)   ]


  # This is the ultimate goal: 
    group <- "Season"    # to use a string variable to pick the grouping 
    DT[, min(which(DT[,get(group)]==G)), by=list(G=get(group))   ]


# WHERE DATA IS: 


DT <- data.table(
structure(list(value = c(0.6264, 0.5711, 0.5906, 0.3939, 0.5126, 
0.5864, 0.6065, 0.4884, 0.5936, 0.6101, 0.474, 0.4988, 0.4541, 
0.5186, 0.6149, 0.5289, 0.5685, 0.6315, 0.5495, 0.6014, 0.6234, 
0.6401, 0.3689, 0.5854, 0.5649, 0.5495, 0.486, 0.6162, 0.5712, 
0.5186), Season = structure(c(1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 4L, 4L, 4L), .Label = c("Winter", "Spring", "Summer", 
"Fall"), class = "factor"), state = structure(c(13L, 16L, 18L, 
13L, 2L, 2L, 18L, 4L, 9L, 18L, 15L, 2L, 8L, 2L, 4L, 6L, 3L, 19L, 
14L, 1L, 11L, 11L, 3L, 15L, 17L, 5L, 12L, 7L, 10L, 2L), .Label = c("AL", 
"CA", "CT", "DC", "IA", "ID", "KY", "MN", "ND", "NH", "NJ", "NV", 
"NY", "OH", "PA", "SD", "TN", "TX", "WA"), class = "factor"), 
    InitState1 = structure(c(2.48, -0.42, -0.42, -0.42, -0.42, 
    -0.42, 2.48, -0.42, -0.42, -0.42, -0.42, -0.42, 2.48, 2.48, 
    -0.42, -0.42, -0.42, 2.48, -0.42, -0.42, -0.42, -0.42, -0.42, 
    -0.42, -0.42, -0.23, -0.42, -0.42, -0.42, 2.48), "``scaled:center``" = 0.144359696361454, "``scaled:scale``" = 0.345329861750493), 
    InitState2 = structure(c(-0.4, -0.4, -0.4, -0.4, -0.4, -0.4, 
    -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, 
    -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, 2.63, -0.4, -0.13, 
    -0.4, -0.4, 2.63, -0.4), "``scaled:center``" = 0.131971251265627, "``scaled:scale``" = 0.330522397541993)), .Names = c("value", 
"Season", "state", "InitState1", "InitState2"), class = c("data.table", 
"data.frame"), row.names = c(NA, -30L)))
