[R] Adding SORT to UNIQUE
Rui Barradas
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Mon Dec 20 18:05:33 CET 2021
Hello,
Package stringr has functions str_sort and str_order, both with an
argument 'numeric' that will sort the numbers correctly.
Maybe that's what you are looking for, see the example below.
x <- sample(sprintf("ab%d", 1:20)) # shuffle the vector
stringr::str_sort(x, numeric = TRUE) # sort considering the numbers
Hope this helps,
Rui Barradas
Às 16:58 de 20/12/21, Stephen H. Dawson, DSL via R-help escreveu:
> Hi,
>
>
> Running a simple syntax set to review entries in dataframe columns. Here
> is the working code.
>
> Data <- read.csv("./input/Source.csv", header=T)
> describe(Data)
> summary(Data)
> unique(Data[1])
> unique(Data[2])
> unique(Data[3])
> unique(Data[4])
>
> I would like to add sort the unique entries. The data in the various
> columns are not defined as numbers, but also text. I realize 1 and 10
> will not sort properly, as the column is not defined as a number, but
> want to see what I have in the columns viewed as sorted.
>
> QUESTION
> What is the best process to sort unique output, please?
>
>
> Thanks.
More information about the R-help
mailing list