[R] Adding SORT to UNIQUE

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Mon Dec 20 19:11:08 CET 2021

Er, I suppose what was wrong was the absence of unique...

as.data.frame( lapply( dta, function(v) sort( unique( v, decreasing = TRUE ) ) ) )

I do think "better" involves value judgements as to whether using one of many specialized tools (tidyverse model) is better or worse than using a sequence of generally-useful tools (base R model). I daily build and re-use my own functions that create verbs for my solution "language"... but I don't necessarily import all of them into every project I use because namespace clutter has both performance and cognitive costs that I prefer to make explicit choices about.

There are real benefits in both sides of this debate, such as avoiding re-inventing the wheel and learning how the language works.

In any event, this is the R-help mailing list, and if there is a cool package that wraps up a tedious base R expression or code chunk then I would hope people would share it, but if possible also provide some equivalent base R code to stay on topic.

On December 20, 2021 9:26:24 AM PST, Jeff Newmiller <jdnewmil using dcn.davis.ca.us> wrote:
>What is wrong with
>as.data.frame(lapply( Data, sort, decreasing = TRUE ))
>On December 20, 2021 8:58:48 AM PST, "Stephen H. Dawson, DSL via R-help" <r-help using r-project.org> wrote:
>>Running a simple syntax set to review entries in dataframe columns. Here 
>>is the working code.
>>Data <- read.csv("./input/Source.csv", header=T)
>>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.
>>What is the best process to sort unique output, please?

Sent from my phone. Please excuse my brevity.

More information about the R-help mailing list