Re: [R] Selecting elements

2021-08-20 Thread Jeff Newmiller
Well, I don't think language is as much of a problem as your failure to compose your messages using plain text format. Your examples are all mushed together since the mailing list removes formatting. See what we see below for example. On August 20, 2021 12:27:50 PM PDT, Silvano Cesar da Costa

Re: [R] Find "undirected" duplicates in a tibble

2021-08-20 Thread Bert Gunter
Thanks, Greg. Turns out that there's an even faster alternative. Note that the OP asked whether one could include in the result the counts of each unordered pair, which I assume could be either 2 or 1. This can be done easily using table(), and it's quite a bit faster for my 1 million pair example

Re: [R] Find "undirected" duplicates in a tibble

2021-08-20 Thread Greg Minshall
Bert, > The efficiency gains are due to vectorization and the use of more > efficient primitives. None of this may matter of course, but it seemed > worth mentioning. thanks very much! the varieties of code, and disparities of performance, are truly wonderful. Rui's point that what works better

Re: [R] Selecting elements

2021-08-20 Thread Silvano Cesar da Costa
Hi, thanks you for the answer. Sorry English is not my native language. But you got it right. > As C is first and fourth biggest value, you follow third option and select 3 highest A, 3B 2C and 2D? I must select the 10 (not 15) highest values, but which follow a certain order: 3A - 3B - 2C - 2D

Re: [R] Find "undirected" duplicates in a tibble

2021-08-20 Thread Bert Gunter
Note that: 1. Your solution returns a matrix, not a data frame (or Tibble) 2. Assuming that the order of the entries in the pairs does not matter (which your solution also assumes and seems reasonable given the OP's specification), I think that you'll find the following, which returns the data.fra

Re: [R] Find "undirected" duplicates in a tibble

2021-08-20 Thread Gabor Grothendieck
Since you are dealing with graphs you could consider using the igraph package. This is more involved than needed for what you are asking but it might be useful for other follow on calculations. We first define a 2 column matrix of edges, then convert it to an igraph and simplify it to remove dupli

Re: [R] Find "undirected" duplicates in a tibble

2021-08-20 Thread Eric Berger
Nice Rui. Here's a version in base R with no apply(). unique(data.frame(V1=pmin(x$Source,x$Target), V2=pmax(x$Source,x$Target))) On Fri, Aug 20, 2021 at 6:43 PM Rui Barradas wrote: > Hello, > > This seems elegant to me but it's also the slowest, courtesy sort. > > apply(x, 1, sort) |> t() |> un

Re: [R] Find "undirected" duplicates in a tibble

2021-08-20 Thread Rui Barradas
Hello, This seems elegant to me but it's also the slowest, courtesy sort. apply(x, 1, sort) |> t() |> unique() (My tests show that for small inputs Greg's base apply is fastest, with nrow(x) > 700, Eric's dplyr is fastest) Hope this helps, Rui Barradas Às 15:13 de 20/08/21, Greg Minshall

Re: [R] Find "undirected" duplicates in a tibble

2021-08-20 Thread Greg Minshall
Eric, > x %>% transmute( a=pmin(Source,Target), b=pmax(Source,Target)) %>% > unique() %>% rename(Source=a, Target=b) ah, very nice. i have trouble remembering, e.g., unique(). fwiw, (hopefully) here's a baser version. x = data.frame(Source=rep(1:3,4), Target=c(rep(1,3),rep(2,3),rep(3,

Re: [R] Find "undirected" duplicates in a tibble

2021-08-20 Thread Eric Berger
x %>% transmute( a=pmin(Source,Target), b=pmax(Source,Target)) %>% unique() %>% rename(Source=a, Target=b) On Fri, Aug 20, 2021 at 2:12 PM Greg Minshall wrote: > Kimmo, > > i'll be curious to see other, maybe more elegant, answers. in the > meantime, this seems to work. > > > x = dat

Re: [R] Find "undirected" duplicates in a tibble

2021-08-20 Thread Greg Minshall
Kimmo, i'll be curious to see other, maybe more elegant, answers. in the meantime, this seems to work. x = data.frame(Source=rep(1:3,4), Target=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3))) y <- apply(x, 1, function(y) return (c(n=min(y), x=max(y res <- data.frame() for (n in unique(

[R] Find "undirected" duplicates in a tibble

2021-08-20 Thread Kimmo Elo
Hi! I am working with a large network data consisting of source-target pairs stored in a tibble. Now I need to transform the directed dataset to an undirected network data. This means, I need to keep only one instance for pairs with the same "nodes". In other words, if my data has one row with A (

Re: [R] Selecting elements

2021-08-20 Thread Jeff Newmiller
Agreed. Need the rest of a complete example. On August 19, 2021 11:27:59 PM PDT, PIKAL Petr wrote: >Hallo > >I am confused, maybe others know what do you want but could you be more >specific? > >Let say you have such data >set.seed(123) >Var.1 = rep(LETTERS[1:4], 10) >Var.2 = sample(1:40, replac

Re: [R] Help needed in double bar plot made using ggplot2

2021-08-20 Thread ken
Thanks Dr. Burradas too. i also had the same question. regards August 20, 2021 6:02 AM, "bharat rawlley via R-help" wrote: > Thank you, Dr. Burradas! > That resolved my query > Have a great rest of your day > On Thursday, 19 August, 2021, 04:47:42 pm GMT-4, Rui Barradas > wrote: > __