Description Usage Arguments Value Functions dependant on this Functions needed in this Examples
View source: R/prep_char_num_sort.R
This is a function which can be used to sort arrays of numeric and characters. This allows you to get numbers into order as characters. e.g. (1,2,100) rather than alphabetical (1,100,2). This can sometimes when creating other functions which require you to have character inputs, as these quite often will cause values to be out of place. NOTE: This function uses regex to determine what counts as a string, if some columns have symbols, they may fail to be read.
1 2 3 4 5 6 7 | prep_char_num_sort(
array,
NA_val = "_NA",
char_decreasing = FALSE,
num_decreasing = FALSE,
unique_val = FALSE
)
|
array |
Array[Character] - This is the array which we want to sort. (If you create c(1,2,"3") they all get assigned character.) |
NA_val |
Character/Numeric/NA (Default = "NA") - This is the value which we want to put NAs as. I recommend using "_NA" when you need to treat NAs as a character to get it positioned near the start rather than in the middle which "NA" would do. If NA is not NA and cannot be converted to numeric, NA will get treated as character and therefore get affected by char_decreasing. |
char_decreasing |
Boolean/NULL (Default = FALSE) - Set this to TRUE if you want character values sorted into descending order. Set to NULL if you do not want character values sorted. |
num_decreasing |
Boolean/NULL (Default = FALSE) - Set this to TRUE if you want numeric values sorted into descending order. Set to NULL if you do not want numeric values sorted. |
unique |
Boolean (Default = TRUE) - Set this to true if you want unique sorted outputs after handling NAs. |
Array[Character] - This will be the entries in array_to_sort sorted. Sections sorted are dependent on char_decreasing and num_decreasing. This could be unique dependent on the parameter "unique". Note that all of these will be character values.
expl_band_cond_shift
check_all_identical
1 2 3 | prep_char_num_sort(c("100","-100","1","-1","_","-","''","CAT","LLAMA","NA","NULL",NA,NULL),NA_val = 2)
# Output: c("''","-","_","CAT","LLAMA","NA","NULL","-100","-1","1","2","100")
prep_char_num_sort(c("C","M","T","-55555","-44444","-33333","0",NA),NA_val = "-1")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.