| seqToSQL | R Documentation |
This function takes as its argument a vector of integers or numeric values, and converts sequential runs to a range while keeping non-sequential values as-is. For example, c(1, 5, 6, 7, 8, 9, 15, 16, 20) becomes "1,5-9,15-16,20". This reduces the number of characters necessary to supply to a SQL condition. This function is mainly of use to developers.
seqToSQL(x, maxChar = 29900, sort = TRUE)
x |
A vector of numerical values. The vector should be sorted from lowers to highest for the most efficient "compression" of sequential ranges. Values will be coerced to class |
maxChar |
Integer or numeric: Maximum number of characters to include in the output. If the output has more than this number of characters, the remainder is dropped, and the |
sort |
Logical: If |
A character string. The string has three attributes. The trim attribute is TRUE or FALSE, depending on whether maxChar was reached or not (and subsequent numbers dropped from the string). The lastIndex attribute is the last index of x that was processed (i.e., the index of the last value in the output), and the number of values represented by the output.
x <- 1:5
seqToSQL(x)
x <- c(1:5, 7)
seqToSQL(x)
x <- c(1:5, 7, 15:16)
y <- c(1:5, 7, 15:16, 20)
seqToSQL(x)
seqToSQL(y)
seqToSQL(x, maxChar = 5)
seqToSQL(y, maxChar = 8)
seqToSQL(10:1, sort = FALSE)
seqToSQL(10:1, sort = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.