# this is a great example of when to use 
#   x <- `ifelse(. . .)` instead of 
#   x <- `if(.) . else .


# DATA 
S <- structure(list(name = c("Epitaph Records", "The Spill Canvas", "Motion City Soundtrack", "The Summer Set", "The Cab"), artistID = c(1L, 2L, 3L, 6L, 7L), Date = c("2012-01-01", "2012-01-01", "2012-01-01", "2012-01-01", "2012-01-01"), iTunesAlbums = c(NA, 35664.09, 16896.82, NA, 34799.27), iTunesTracks = c(NA, 43153.1, 7128.74, NA, 37219.06), iTunesVideo = c(NA, 145.01, 125.95, NA, 751.72), DirectPOS = c(NA, NA, 677.83, NA, NA)), .Names = c("name", "artistID", "Date", "iTunesAlbums", "iTunesTracks", "iTunesVideo", "DirectPOS"), sorted = "artistID", class = c("data.table", "data.frame"), row.names = c(NA, -5L), .internal.selfref = <pointer: 0x107006978>)


# SHOULD BE ifelse
  for (COLUMN in names(salesCols))
    S[, paste0(COLUMN, ".rank") := if(is.na(get(COLUMN))) NA else order(order(get(COLUMN), na.last=TRUE, decreasing=TRUE))]

  setcolorder(S, orderedColumns(S))
  S

# AS SO
  for (COLUMN in names(salesCols))
    S[, paste0(COLUMN, ".rank") := ifelse(is.na(get(COLUMN)),  NA, order(order(get(COLUMN), na.last=TRUE, decreasing=TRUE)))]

  setcolorder(S, orderedColumns(S))
  S


                       name artistID       Date DirectPOS DirectPOS.rank iTunesAlbums iTunesAlbums.rank iTunesTracks iTunesTracks.rank iTunesVideo iTunesVideo.rank
1:        Epitaph Records        1 2012-01-01        NA             NA           NA                NA           NA                NA          NA               NA
2:       The Spill Canvas        2 2012-01-01        NA             NA     35664.09                 1     43153.10                 1      145.01                2
3: Motion City Soundtrack        3 2012-01-01    677.83              1     16896.82                 3      7128.74                 3      125.95                3
4:         The Summer Set        6 2012-01-01        NA             NA           NA                NA           NA                NA          NA               NA
5:                The Cab        7 2012-01-01        NA             NA     34799.27                 2     37219.06                 2      751.72                1
