Re: [R] Adding SORT to UNIQUE

2021-12-23 Thread Stephen H. Dawson, DSL via R-help
Hi Duncan, Thanks for the reply. You bring much insight to the equation of the R journey. I look forward to dialoging with you. *Stephen Dawson, DSL* /Executive Strategy Consultant/ Business & Technology +1 (865) 804-3454 http://www.shdawson.com On 12/22/21 12:12

Re: [R] Adding SORT to UNIQUE

2021-12-23 Thread Stephen H. Dawson, DSL via R-help
nal Message- From: R-help On Behalf Of Stephen H. Dawson, DSL via R-help Sent: Wednesday, December 22, 2021 10:55 AM To: Duncan Murdoch ; Rui Barradas ; Stephen H. Dawson, DSL via R-help Subject: Re: [R] Adding SORT to UNIQUE I see. So, we are talking taking the output into a new datafr

Re: [R] Adding SORT to UNIQUE

2021-12-23 Thread Stephen H. Dawson, DSL via R-help
v1, justify = "right"), sep = "\n") -Original Message- From: R-help On Behalf Of Stephen H. Dawson, DSL via R-help Sent: Wednesday, December 22, 2021 12:02 PM To: Duncan Murdoch ; Rui Barradas ; Stephen H. Dawson, DSL via R-help Subject: Re: [R] Adding SORT to

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Rui Barradas
") -Original Message- From: R-help On Behalf Of Stephen H. Dawson, DSL via R-help Sent: Wednesday, December 22, 2021 12:02 PM To: Duncan Murdoch ; Rui Barradas ; Stephen H. Dawson, DSL via R-help Subject: Re: [R] Adding SORT to UNIQUE Data <- read.csv("./input

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Stephen H. Dawson, DSL via R-help
to have that name, this would do it: cat(format(names(Data[,1]). "\n", v1, justify = "right"), sep = "\n") -Original Message- From: R-help On Behalf Of Stephen H. Dawson, DSL via R-help Sent: Wednesday, December 22, 2021 12:02 PM To: Duncan Murdoch ; R

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Avi Gross via R-help
adas ; Stephen H. Dawson, DSL via R-help Subject: Re: [R] Adding SORT to UNIQUE Data <- read.csv("./input/Source.csv", header=T) v1 <- sort(unique(Data[, 1])) cat(format(v1, justify = "right"), sep = "\n") OK, working with the options you presented. This is the

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Duncan Murdoch
On 22/12/2021 12:01 p.m., Stephen H. Dawson, DSL wrote: Data <- read.csv("./input/Source.csv", header=T) v1 <- sort(unique(Data[, 1])) cat(format(v1, justify = "right"), sep = "\n") OK, working with the options you presented. This is the combination where I gain the most benefit. However,

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Stephen H. Dawson, DSL via R-help
Wow! Thanks. I need to process the logic you have presented next week when I have the time to focus. I now need to accomplish some productive work output based on what I have now for understandings. Kindest Regards, *Stephen Dawson, DSL* /Executive Strategy Consultant/ Business & Technology

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Stephen H. Dawson, DSL via R-help
Data <- read.csv("./input/Source.csv", header=T) v1 <- sort(unique(Data[, 1])) cat(format(v1, justify = "right"), sep = "\n") OK, working with the options you presented. This is the combination where I gain the most benefit. However, there is no listing of a column header with the output of

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Avi Gross via R-help
cember 22, 2021 10:55 AM To: Duncan Murdoch ; Rui Barradas ; Stephen H. Dawson, DSL via R-help Subject: Re: [R] Adding SORT to UNIQUE I see. So, we are talking taking the output into a new dataframe. I was hoping to have the output rendered on screen without another dataframe, but I can

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Rui Barradas
Hello, The problem is that the vectors of unique values in each column of the original data.frame Data need not be same length. And the output of sort(unique(.)) is a list of vectors of different lengths. And lists print "horizontally", each vector on its own. Like Duncan said, one of the

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Stephen H. Dawson, DSL via R-help
OK, now I get what you are suggesting. Much appreciated. Kindest Regards, *Stephen Dawson, DSL* /Executive Strategy Consultant/ Business & Technology +1 (865) 804-3454 http://www.shdawson.com On 12/22/21 11:08 AM, Duncan Murdoch wrote: On 22/12/2021 10:55 a.m.,

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Duncan Murdoch
On 22/12/2021 10:55 a.m., Stephen H. Dawson, DSL wrote: I see. So, we are talking taking the output into a new dataframe. I was hoping to have the output rendered on screen without another dataframe, but I can live with this option it if must occur. Am I correct the desired vertical output

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Stephen H. Dawson, DSL via R-help
I see. So, we are talking taking the output into a new dataframe. I was hoping to have the output rendered on screen without another dataframe, but I can live with this option it if must occur. Am I correct the desired vertical output must first go to a dataframe? *Stephen Dawson, DSL*

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Stephen H. Dawson, DSL via R-help
ke it a good idea to find someone sharing a package where they did the hard work and documented exactly what their function does. I am eclectic and happy to switch tools at a moment's notice if they offer an interesting way to do something. But, within a language, I learn the darn rules and also th

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Duncan Murdoch
On 22/12/2021 10:20 a.m., Stephen H. Dawson, DSL wrote: Thanks for the reply. Both syntax options work to render the correct (unique) output. However, the output is rendered as horizontal. What needs to happen to get the output to render vertical, please? The result of those expressions is a

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Stephen H. Dawson, DSL via R-help
Bert, Thanks for the reply. I did not think to put values back into the same column. This action would not make sense to me, as it would destroy data integrity. I guess adding to a new column in the same container, in this case a dataframe, is possible but again not probable with me.

Re: [R] Adding SORT to UNIQUE

2021-12-22 Thread Stephen H. Dawson, DSL via R-help
Thanks for the reply. Both syntax options work to render the correct (unique) output. However, the output is rendered as horizontal. What needs to happen to get the output to render vertical, please? *Stephen Dawson, DSL* /Executive Strategy Consultant/ Business & Technology +1 (865)

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Bert Gunter
Stephen: You seem confused about data frames. sort(unique(...)) has no problem sorting individual columns in a data frame (mod the issues about mixing numerics and non-numerics that have already been discussed). But the problem is that the results can *not* be put back in a data frame because,

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Jeff Newmiller
It is not about outlawing matrix notation... to the contrary, it is about consistency. For tibbles, [] always returns another tibble. If you wanted a column vector, you should have asked for a column vector. Does the fact that DF[ 1, ] yields a different type than DF[ , 1 ] and DF[ 1:2, ]

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Fox, John
Dear Jeff, I haven't investigated your claim systematically, but out of curiosity, I did try extending my previous example, admittedly arbitrarily. In doing so, I assumed that you intended col in the first case to be the column subscript, not the row subscript. Here's what I got (on a newish

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Avi Gross via R-help
t.org; serv...@shdawson.com; Rui Barradas Subject: Re: [R] Adding SORT to UNIQUE On 21/12/2021 11:59 a.m., Jeff Newmiller wrote: > Intuitive, perhaps, but noticably slower. And it doesn't work on tibbles by > design. Data frames are lists of columns. That's just one of the design flaws

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Avi Gross via R-help
and happy to switch tools at a moment's notice if they offer an interesting way to do something. But, within a language, I learn the darn rules and also the idioms often used and then choose from among many ways I can see to solve something and use what is available. You had a trivial solution

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Duncan Murdoch
On 21/12/2021 12:53 p.m., Duncan Murdoch wrote: On 21/12/2021 12:29 p.m., Jeff Newmiller wrote: It is a very rational choice, not a design flaw. I don't like every choice they have made for that class, but this one is very solid, and treating data frames as lists of columns consistently helps

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Jeff Newmiller
When your brain is wired to treat a data frame like a matrix, then you think things like for ( col in colnames( col ) ) { idx <- expr D[ col, idx ] <- otherexpr } are reasonable, when for ( col in colnames( col ) ) { idx <- expr D[[ col ]][ idx ] <- otherexpr } does actually run

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Duncan Murdoch
On 21/12/2021 12:29 p.m., Jeff Newmiller wrote: It is a very rational choice, not a design flaw. I don't like every choice they have made for that class, but this one is very solid, and treating data frames as lists of columns consistently helps all of us. I think outlawing matrix notation is

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Jeff Newmiller
It is a very rational choice, not a design flaw. I don't like every choice they have made for that class, but this one is very solid, and treating data frames as lists of columns consistently helps all of us. On December 21, 2021 9:02:56 AM PST, Duncan Murdoch wrote: >On 21/12/2021 11:59

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Fox, John
Dear Jeff, On 2021-12-21, 11:59 AM, "R-help on behalf of Jeff Newmiller" wrote: Intuitive, perhaps, but noticably slower. I think that in most applications, one wouldn't notice the difference; for example: > D <- data.frame(matrix(rnorm(1000*1e6), 1e6, 1000)) > microbenchmark(D[, 1])

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Duncan Murdoch
On 21/12/2021 11:59 a.m., Jeff Newmiller wrote: Intuitive, perhaps, but noticably slower. And it doesn't work on tibbles by design. Data frames are lists of columns. That's just one of the design flaws in tibbles, but not the worst one. Duncan Murdoch On December 21, 2021 8:38:35 AM PST,

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Jeff Newmiller
Intuitive, perhaps, but noticably slower. And it doesn't work on tibbles by design. Data frames are lists of columns. On December 21, 2021 8:38:35 AM PST, Duncan Murdoch wrote: >On 21/12/2021 11:31 a.m., Duncan Murdoch wrote: >> On 21/12/2021 11:20 a.m., Stephen H. Dawson, DSL wrote: >>>

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Duncan Murdoch
On 21/12/2021 11:31 a.m., Duncan Murdoch wrote: On 21/12/2021 11:20 a.m., Stephen H. Dawson, DSL wrote: Thanks for the reply. sort(unique(Data[1])) Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) :   undefined columns selected That's the wrong syntax:

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Duncan Murdoch
On 21/12/2021 11:20 a.m., Stephen H. Dawson, DSL wrote: Thanks for the reply. sort(unique(Data[1])) Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) :   undefined columns selected That's the wrong syntax: Data[1] is not "column one of Data". Use Data[[1]]

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Stephen H. Dawson, DSL via R-help
Thanks for the reply. sort(unique(Data[1])) Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) :   undefined columns selected The recommended syntax did not work, as listed above. What I want is the sort of distinct column output. Again, the column may be text

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Duncan Murdoch
On 21/12/2021 10:16 a.m., Stephen H. Dawson, DSL via R-help wrote: Thanks everyone for the replies. It is clear one either needs to write a function or put the unique entries into another dataframe. It seems odd R cannot sort a list of unique column entries with ease. Python and SQL can do it

Re: [R] Adding SORT to UNIQUE

2021-12-21 Thread Stephen H. Dawson, DSL via R-help
Thanks everyone for the replies. It is clear one either needs to write a function or put the unique entries into another dataframe. It seems odd R cannot sort a list of unique column entries with ease. Python and SQL can do it with ease. QUESTION Is there a simpler means than other than

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Rui Barradas
Hello, Inline. Às 21:18 de 20/12/21, Stephen H. Dawson, DSL via R-help escreveu: Thanks. sort(unique(Data[[1]])) This syntax provides row numbers, not column values. This is not right. The syntax Data[1] extracts a sub-data.frame, the syntax Data[[1]] extracts the column vector. As for

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Avi Gross via R-help
nd of set, and there are ways to also use sets in R. -Original Message- From: R-help On Behalf Of Duncan Murdoch Sent: Monday, December 20, 2021 12:51 PM To: Martin Maechler ; Rui Barradas Cc: Stephen H. Dawson, DSL via R-help Subject: Re: [R] Adding SORT to UNIQUE On 20/12/2021 12:32

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Stephen H. Dawson, DSL via R-help
Thanks for the reply. sort(unique(Data[1])) Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) :   undefined columns selected The recommended syntax did not work, as listed above. *Stephen Dawson, DSL* /Executive Strategy Consultant/ Business & Technology +1

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Stephen H. Dawson, DSL via R-help
Thanks. sort(unique(Data[[1]])) This syntax provides row numbers, not column values. *Stephen Dawson, DSL* /Executive Strategy Consultant/ Business & Technology +1 (865) 804-3454 http://www.shdawson.com On 12/20/21 11:58 AM, Stephen H. Dawson, DSL via R-help wrote:

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Stephen H. Dawson, DSL via R-help
Thanks for the reply. sort(unique(Data[1])) Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) :   undefined columns selected The recommended syntax did not work, as listed above. *Stephen Dawson, DSL* /Executive Strategy Consultant/ Business & Technology +1

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Bert Gunter
Martin: I think the issue is this: > sort(c('a10','a1','a3')) [1] "a1" "a10" "a3" > ## wanted 'a1', 'a3', 'a10' ?? The OP would have to confirm, of course. If he only wanted to sort just numerics, coercing to numeric first would presumably handle it. For situations like the above, one probably

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Jeff Newmiller
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

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Duncan Murdoch
On 20/12/2021 12:32 p.m., Martin Maechler wrote: Rui Barradas on Mon, 20 Dec 2021 17:05:33 + writes: > 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

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Avi Gross via R-help
-project.org Subject: Re: [R] Adding SORT to UNIQUE Thanks for the reply. sort(unique(Data[1])) Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) : undefined columns selected The recommended syntax did not work, as listed above. Stephen Dawson, DSL Executive

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Martin Maechler
> Rui Barradas > on Mon, 20 Dec 2021 17:05:33 + writes: > 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.

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Jeff Newmiller
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" wrote: >Hi, > > >Running a simple syntax set to review entries in dataframe columns. Here >is the working code. > >Data <-

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Avi Gross via R-help
Stephen, You can sort using sort() either before or after doing a unique. Unique removes all duplicates in any order so sorting before may be wasteful. in your data shown below, do this: sort(unique(Data[1])) sort(unique(Data[2])) sort(unique(Data[3])) sort(unique(Data[4])) Even simpler is to

Re: [R] Adding SORT to UNIQUE

2021-12-20 Thread Rui Barradas
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)