Re: [R] Find tibble row with maximum recorded value

2021-12-04 Thread Avi Gross via R-help
. Without clear requirements, there often is no right answer. -Original Message- From: R-help On Behalf Of Rui Barradas Sent: Saturday, December 4, 2021 2:34 AM To: Bert Gunter Cc: R-help Subject: Re: [R] Find tibble row with maximum recorded value Hello, You're right, I carelessly coded

Re: [R] Find tibble row with maximum recorded value

2021-12-03 Thread Rui Barradas
Hello, You're right, I carelessly coded this. which.max returns the index to the first maximum of a vector, while the comparison of a vector with its max() returns an index to all vector elements. Às 23:27 de 03/12/21, Bert Gunter escreveu: Perhaps you meant to point this out, but the

Re: [R] Find tibble row with maximum recorded value

2021-12-03 Thread Rich Shepard
On Fri, 3 Dec 2021, Rich Shepard wrote: they apparently do. For example, 99.9000 cubic feet per second is reached 99,900 Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

Re: [R] Find tibble row with maximum recorded value

2021-12-03 Thread Rich Shepard
On Fri, 3 Dec 2021, Bert Gunter wrote: Perhaps you meant to point this out, but the cfs[which.max(cfs)] and cfs == ... are not the same: x <- rep(1:2,3) x [1] 1 2 1 2 1 2 x[which.max(x)] [1] 2 x[x==max(x)] [1] 2 2 2 So maybe your point is: which does the OP want (in case there are

Re: [R] Find tibble row with maximum recorded value

2021-12-03 Thread Bert Gunter
Perhaps you meant to point this out, but the cfs[which.max(cfs)] and cfs == ... are not the same: > x <- rep(1:2,3) > x [1] 1 2 1 2 1 2 > x[which.max(x)] [1] 2 > x[x==max(x)] [1] 2 2 2 So maybe your point is: which does the OP want (in case there are repeated maxes)? I suspect the == forms, but

Re: [R] Find tibble row with maximum recorded value

2021-12-03 Thread Rich Shepard
On Fri, 3 Dec 2021, Rui Barradas wrote: which.max(pdx_disc$cfs) [1] 8054 This is the *index* for which cfs is the first maximum, not the maximum value itself. Rui, Mea culpa! I completely forgot this. Therefore, you probably want any of filter(pdx_disc, cfs == cfs[8054])

Re: [R] Find tibble row with maximum recorded value

2021-12-03 Thread Rui Barradas
Hello, Inline. Às 22:08 de 03/12/21, Rich Shepard escreveu: On Fri, 3 Dec 2021, Rich Shepard wrote: I find solutions when the data_frame is grouped, but none when it's not. Thanks, Bert. ?which.max confirmed that's all I need to find the maximum value. Now I need to read more than ?filter

Re: [R] Find tibble row with maximum recorded value

2021-12-03 Thread Rich Shepard
On Fri, 3 Dec 2021, Rich Shepard wrote: I find solutions when the data_frame is grouped, but none when it's not. Thanks, Bert. ?which.max confirmed that's all I need to find the maximum value. Now I need to read more than ?filter to learn why I'm not getting the relevant row with:

Re: [R] Find tibble row with maximum recorded value

2021-12-03 Thread Rich Shepard
On Fri, 3 Dec 2021, Jeff Newmiller wrote: cfs is not a function. Don't put parentheses next to it. Use square brackets for indexing. Jeff, Thanks. Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

Re: [R] Find tibble row with maximum recorded value

2021-12-03 Thread Jeff Newmiller
cfs is not a function. Don't put parentheses next to it. Use square brackets for indexing. On December 3, 2021 12:55:34 PM PST, Rich Shepard wrote: >I find solutions when the data_frame is grouped, but none when it's not. > >The data: ># A tibble: 813,693 × 9 >site_nbr year mon day

Re: [R] Find tibble row with maximum recorded value

2021-12-03 Thread Bert Gunter
which.max(dat$cfs), I presume. see ?which.max (as usual, true tidyverse questions belong on RStudio's help site, not here). Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic

[R] Find tibble row with maximum recorded value

2021-12-03 Thread Rich Shepard
I find solutions when the data_frame is grouped, but none when it's not. The data: # A tibble: 813,693 × 9 site_nbr year mon dayhr min tz cfs sampdt 1 14211720 198810 1 010 PDT 16800 1988-10-01 00:10:00 2 14211720 198810 1 0

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

2021-08-23 Thread Kimmo Elo
Hi! Thank you very much for the fascinating solutions. Nice to learn different approaches. All solutions seem to work with text data as well. @Gabor (who suggested the 'igraph' package): yes, I am familiar with 'igraph' and the solution suggested by you works fine, too. Since I need this kind of

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

2021-08-21 Thread Greg Minshall
Bert, > Turns out that there's an even faster alternative. hah, but i'm *not* surprised. thanks for sharing the (current) low-price leader! and, thanks, again, to Kimmo for posting such a productive question! cheers, Greg my apply user system elapsed 8.465 0.103 8.578 Bert's

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

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

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

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

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() |>

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

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),

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 =

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

[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] Find the number of clusters using clusGAP function in R

2021-01-20 Thread John Kane
Crossposted at https://community.rstudio.com/t/find-the-number-of-clusters-using-clusgap-function-in-r/93586 There is nothing wrong with crossposting but one should mention it to help avoid duplication of effort On Wed, 20 Jan 2021 at 09:46, Jovani T. de Souza wrote: > Could you help me find

[R] Find the number of clusters using clusGAP function in R

2021-01-20 Thread Jovani T. de Souza
Could you help me find the ideal number of clusters using the `clusGap `function? There is a similar example in this link: https://www.rdocumentation.org/packages/factoextra/versions/1.0.7/topics/fviz_nbclust But I would like to do it for my case. My code is below: library(cluster) df

Re: [R] FInd packages in need of Update (like RStudio)

2020-12-23 Thread Dr Eberhard W Lisse
Or rather Rscript -e 'local({r <- getOption("repos");r["CRAN"] <- "https://cloud.r-project.org/";options(repos = r)});update.packages(dependencies = TRUE, ask=FALSE)' as a one liner :-)-O el On 2020-12-23 17:59 , Dr Eberhard W Lisse wrote: > Thanks, > >

Re: [R] FInd packages in need of Update (like RStudio)

2020-12-23 Thread Dr Eberhard W Lisse
Thank you, but the RFTM suggestion helped me even more :-)-O greetings, el On 2020-12-23 17:06 , Sarah Goslee wrote: > Does update.packages() meet your needs? > > > Sarah > > On Wed, Dec 23, 2020 at 9:39 AM Dr Eberhard W Lisse wrote: >> >> Hi, >> >> does anyone know how one would look which

Re: [R] FInd packages in need of Update (like RStudio)

2020-12-23 Thread Dr Eberhard W Lisse
Thanks, update.packages(dependencies = TRUE, ask=FALSE) does what I want. greetings, el On 2020-12-23 17:30 , Deepayan Sarkar wrote: > On Wed, Dec 23, 2020 at 8:09 PM Dr Eberhard W Lisse wrote: >> >> Hi, >> >> does anyone know how one would look which packages require an update >>

Re: [R] FInd packages in need of Update (like RStudio)

2020-12-23 Thread Deepayan Sarkar
On Wed, Dec 23, 2020 at 8:09 PM Dr Eberhard W Lisse wrote: > > Hi, > > does anyone know how one would look which packages require an update > (like the Tools -> Update Packages) but can do it from R (ie Rscript) or > any other way from the command line (on the MAc) ? old.packages Best,

Re: [R] FInd packages in need of Update (like RStudio)

2020-12-23 Thread Jeff Newmiller
This is not normally something one would apply automatically, as it can break existing code. But wouldn't?update.packages be the obvious choice interactively? On December 23, 2020 6:38:41 AM PST, Dr Eberhard W Lisse wrote: >Hi, > >does anyone know how one would look which packages require an

[R] FInd packages in need of Update (like RStudio)

2020-12-23 Thread Dr Eberhard W Lisse
Hi, does anyone know how one would look which packages require an update (like the Tools -> Update Packages) but can do it from R (ie Rscript) or any other way from the command line (on the MAc) I would like to build this into my update script which currently does brew, cpan and pip3 :-)-O

Re: [R] Find the ideal cluster

2020-12-14 Thread Jovani T. de Souza
Thank you so much! Sorry Michael, I will insert in the next. Best regards. [image: Mailtrack] Remetente notificado por Mailtrack

Re: [R] Find the ideal cluster

2020-12-12 Thread Michael Dewey
Dear Jovani If you cross-post on CrossValidated as well as here it is polite to give a link so people do not answer here when someone has already answered there, or vice versa. Michael On 12/12/2020 15:27, Jovani T. de Souza wrote: So, I and some other colleagues developed a hierarchical

Re: [R] Find the ideal cluster

2020-12-12 Thread David Carlson
Look at the Cluster Analysis Task View, particularly section "Additional Functionality" (https://cran.r-project.org/web/views/Cluster.html) Maybe package clValid: The R package clValid contains functions for validating the results of a clustering analysis. There are three main types of cluster

[R] Find the ideal cluster

2020-12-12 Thread Jovani T. de Souza
So, I and some other colleagues developed a hierarchical clustering algorithm to basically find the main clusters involving agricultural industries according to a particular city (e.g. London city).. We structured this algorithm in R. It is working perfectly. So, according to our filters that we

Re: [R] find local max in moving window

2020-11-13 Thread Rui Barradas
Hello, The best option is package zoo, function(s) rollapply. p <- zoo::rollapply(nordn, width = 15, FUN = max, fill = c(NA, 0, NA)) These are meant as checks, see the differences between the one-liner above and your result. dim(position) length(p) w <- which(position[, 1] == p)

[R] find local max in moving window

2020-11-13 Thread ani jaya
Dear r list, I try to locate any local max value and location of data that follow 7 moving window condition, meaning that this data is largest and centered in 7 values to the left and 7 values to the right. I can solve it by using for and if function, like below: dput(nordn) c(`1` =

Re: [R] find number of consecutive days in NC files by R

2020-09-04 Thread Martin Maechler
> Jeff Newmiller > on Thu, 06 Aug 2020 10:49:50 -0700 writes: > You need to make a small fake dataset that illustrates > what you have and what you want out of it. Telling us you > are not getting what you want is simply not useful. Indeed. In addition: Do *not* use

Re: [R] find number of consecutive days in NC files by R

2020-09-03 Thread Jim Lemon
lt;-getValues(r,format="matrix") > > i<-i+1 > > } > > Best wishes, > > Windows 10 için Posta ile gönderildi > > > > Kimden: Jim Lemon > Gönderilme: 10 Ağustos 2020 Pazartesi 06:28 > Kime: ahmet varlı > Konu: Re: [R] find number of consec

Re: [R] find end of monotonic part of vector

2020-08-10 Thread PIKAL Petr
not having NA within them). Find position of all minimum values. Not sure if this approach will work, though. Cheers Petr > -Original Message- > From: Rui Barradas > Sent: Friday, August 7, 2020 5:45 PM > To: PIKAL Petr ; R-help > Subject: Re: [R] find end of monotonic

Re: [R] find number of consecutive days in NC files by R

2020-08-09 Thread Jim Lemon
m, > > > > Could you help me to remove NA values which are water values ? > > > > > > Kimden: Jim Lemon > Gönderilme: 7 Ağustos 2020 Cuma 22:53 > Kime: ahmet varlı > Konu: Re: [R] find number of consecutive days in NC files by R > > > > There a

Re: [R] find end of monotonic part of vector

2020-08-07 Thread Rui Barradas
Hello, I should have continued, inline. Às 15:05 de 07/08/20, Rui Barradas escreveu: Hello, Maybe I'm not understanding but looking at this graph i <- diff(kalo.v$vodiv) > 0 plot(kalo.v) lines(kalo.v) points(kalo.v$cas[i], kalo.v$vodiv[i], pch = 16, col = "red") it seems you want the

Re: [R] find end of monotonic part of vector

2020-08-07 Thread Rui Barradas
Hello, Maybe I'm not understanding but looking at this graph i <- diff(kalo.v$vodiv) > 0 plot(kalo.v) lines(kalo.v) points(kalo.v$cas[i], kalo.v$vodiv[i], pch = 16, col = "red") it seems you want the point before the first local minimum? min(which(i)) - 1L #[1] 20 Hope this helps, Rui

[R] find end of monotonic part of vector

2020-08-07 Thread PIKAL Petr
Hallo all I have such data > dput(kalo.v) structure(list(cas = structure(c(1595847000, 1595847060, 1595847120, 1595847180, 1595847240, 1595847300, 1595847360, 1595847420, 1595847480, 1595847540, 1595847600, 1595847660, 1595847720, 1595847780, 1595847840, 1595847900, 1595847960, 1595848020,

Re: [R] find number of consecutive days in NC files by R

2020-08-06 Thread Jim Lemon
[,170][,171][,172][,173] [,174][,175] > > [,176][,177][,178][,179][,180][,181][,182] > > > > [1,] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 > > 0.000 0.000 0.000 0.000 0.0

Re: [R] find number of consecutive days in NC files by R

2020-08-06 Thread Jim Lemon
0.000 0.000 0.000 0.000 0.000 0.000 0.000 > > [3,] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 > 0.000 0.0000000 0.000 0.000 0.000 0.000 0.000 > > [4,] 0.358 0.358 0.358 0.358 0.358 0.358 0

Re: [R] find number of consecutive days in NC files by R

2020-08-06 Thread Jim Lemon
Hi Ahmet, I think what you are looking for can be done using run length encoding (rle). # make up some data soil_moisture<-sin(seq(0,4*pi,length.out=730))+1.1 dates<-as.Date(as.Date("2018-01-01"):as.Date("2019-12-31"), origin=as.Date("1970-01-01")) # get a logical vector for your condition

Re: [R] find number of consecutive days in NC files by R

2020-08-06 Thread Jeff Newmiller
You need to make a small fake dataset that illustrates what you have and what you want out of it. Telling us you are not getting what you want is simply not useful. On August 6, 2020 8:58:09 AM PDT, "ahmet varlı" wrote: >Hi all, > > >There are 365 days of soil moisture NC files and I am trying

[R] find number of consecutive days in NC files by R

2020-08-06 Thread ahmet varlı
Hi all, There are 365 days of soil moisture NC files and I am trying to find out how many days the values are below and above this certain threshold are repeated by R. However, I couldn't reach exactly what I wanted. For example, Daily soil moisture is below 0.3 without interrupting how many

Re: [R] find number of consecutive days in NC files

2020-08-05 Thread Jeff Newmiller
rle( x > thresh ) On August 4, 2020 5:10:42 PM PDT, "ahmet varlı" wrote: >There are 365 days of soil moisture NC files and I am trying to find >out how many days the values are below and above this certain threshold >are repeated. However, I couldn't reach exactly what I wanted. > >nctoarray <-

[R] find number of consecutive days in NC files

2020-08-05 Thread ahmet varlı
There are 365 days of soil moisture NC files and I am trying to find out how many days the values are below and above this certain threshold are repeated. However, I couldn't reach exactly what I wanted. nctoarray <- function(ncfname, varid = NA) { nc <- nc_open(ncfname) a <-

Re: [R] find multiple mode, sorry for not providing enough information

2020-03-16 Thread Abby Spurdle
#bug fix unique.consecutive <- function (x) { dx <- diff (x) x [c (TRUE, dx != 0)] } __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

Re: [R] find multiple mode, sorry for not providing enough information

2020-03-16 Thread Yuan Chun Ding
ints=TRUE),] -Original Message- From: Abby Spurdle [mailto:spurdl...@gmail.com] Sent: Monday, March 16, 2020 1:57 PM To: Yuan Chun Ding Cc: Jim Lemon; r-help mailing list Subject: Re: [R] find multiple mode, sorry for not providing enough information (Sorry, that was supposed to go to the

Re: [R] find multiple mode, sorry for not providing enough information

2020-03-16 Thread Abby Spurdle
I think I need a different email. Google is making it difficult to sent/receive/read completely plain text messages. On my end, it's automatically formatting plain text messages, and doing so, incorrectly. __ R-help@r-project.org mailing list -- To

Re: [R] find multiple mode, sorry for not providing enough information

2020-03-16 Thread Abby Spurdle
Sorry, internet's not working properly today. Third time lucky Here's a solution to your original question: - freq <- c (1,2,5,5,10,4,4,8,1,1,8,8,2,4,3,1,2,1,1,138,149,14,1,1) unique.consecutive <- function (x) { dx <- diff (x) x [dx != 0] } which.maxs <- function (x, ...,

Re: [R] find multiple mode, sorry for not providing enough information

2020-03-16 Thread Abby Spurdle
you, > > Ding > > -Original Message- > From: Jim Lemon [mailto:drjimle...@gmail.com] > Sent: Monday, March 16, 2020 1:10 AM > To: Yuan Chun Ding; r-help mailing list > Subject: Re: [R] find multiple mode, sorry for not providing enough > information > &g

Re: [R] find multiple mode, sorry for not providing enough information

2020-03-16 Thread Yuan Chun Ding
-Original Message- From: Jim Lemon [mailto:drjimle...@gmail.com] Sent: Monday, March 16, 2020 1:10 AM To: Yuan Chun Ding; r-help mailing list Subject: Re: [R] find multiple mode, sorry for not providing enough information [Attention: This email came from an external source. Do not open

Re: [R] find multiple mode, sorry for not providing enough information

2020-03-16 Thread Jim Lemon
Hi Ding, While I was completely off the track in my first reply, the subsequent posts make your problem somewhat clearer. The way you state the problem suggests that the order of the values of "freq" is important. That is, it is not just a matter of finding local maxima, but the direction in which

Re: [R] find multiple mode, sorry for not providing enough information

2020-03-15 Thread Jeff Newmiller
uot; > tem <- tem[which(tem$V1!=""),,drop=F] > tem2 <-separate(tem, col=V1, into=c("m1","m2"), convert = T) > tem3 <-gather(tem2, marker, VNTR_repeats, m1:m2) > tem4 <-as.data.frame(t(t(table(tem3$VNTR_repeats[,c(1,3)] > tem4$Var1 <

Re: [R] find multiple mode, sorry for not providing enough information

2020-03-15 Thread Yuan Chun Ding
From: Abby Spurdle [spurdl...@gmail.com<mailto:spurdl...@gmail.com>] Sent: Sunday, March 15, 2020 3:42 PM To: Jim Lemon Cc: Yuan Chun Ding; r-help mailing list Subject: Re: [R] find multiple mode I think people have misinterpreted the question. The OP wa

Re: [R] find multiple mode, sorry for not providing enough information

2020-03-15 Thread Bert Gunter
eparate(tem, col=V1, into=c("m1","m2"), convert = T) > tem3 <-gather(tem2, marker, VNTR_repeats, m1:m2) > tem4 <-as.data.frame(t(t(table(tem3$VNTR_repeats[,c(1,3)] > tem4$Var1 <-as.numeric(as.character(tem4$Var1)) > tem4 <-tem4[order(tem4$Var1),]

Re: [R] find multiple mode

2020-03-15 Thread Yuan Chun Ding
- } From: R-help [r-help-boun...@r-project.org] on behalf of Duncan Murdoch [murdoch.dun...@gmail.com] Sent: Sunday, March 15, 2020 4:20 PM To: Abby Spurdle; Jim Lemon Cc: r-help mailing list Subject: Re: [R] find

Re: [R] find multiple mode, sorry for not providing enough information

2020-03-15 Thread Yuan Chun Ding
<-as.data.frame(t(t(table(tem3$VNTR_repeats[,c(1,3)] tem4$Var1 <-as.numeric(as.character(tem4$Var1)) tem4 <-tem4[order(tem4$Var1),] m<- From: Abby Spurdle [spurdl...@gmail.com] Sent: Sunday, March 15, 2020 3:42 PM To: Jim Lemon Cc:

Re: [R] find multiple mode

2020-03-15 Thread Duncan Murdoch
On 15/03/2020 6:42 p.m., Abby Spurdle wrote: I think people have misinterpreted the question. The OP wants local maxima from the series. The original series is frequencies, so your table is frequencies of frequencies. A solution can be derived by looking at signs of the first and second

Re: [R] find multiple mode

2020-03-15 Thread Abby Spurdle
I think people have misinterpreted the question. The OP wants local maxima from the series. The original series is frequencies, so your table is frequencies of frequencies. A solution can be derived by looking at signs of the first and second differences. But there may be a simpler way On

Re: [R] find multiple mode

2020-03-15 Thread Rui Barradas
Hello, There is StackOverflow question on mode finding [1]. There is also a RPubs post, with the following now rewritten as a function. Mode <- function(x){ y <- table(x) names(y)[which(y == max(y))] } Mode(freq) #[1] "1" is.na(freq) <- freq == 1 Mode(freq) #[1] "2" "4" "8" [1]

Re: [R] find multiple mode

2020-03-15 Thread Sorkin, John
ailto:ycd...@coh.org> Sent: Sunday, March 15, 2020 4:55 PM To: r-help mailing list<mailto:r-help@r-project.org> Subject: [R] find multiple mode Hi R users, I want to find multiple modes (10, 8, 149) for the following vector. freq =1,2,5,5 10,4,4,8,1,1,8,8,2,4,3,1,2,1,1 138 149 14,1,1; any sugg

Re: [R] find multiple mode

2020-03-15 Thread Jim Lemon
Hi Ding, Translating this into R code: freq<-c(1,2,5,5,10,4,4,8,1,1,8,8,2,4,3,1,2,1,1,138,149,14,1,1) > table(freq) freq 1 2 3 4 5 8 10 14 138 149 8 3 1 3 2 3 1 1 1 1 > library(prettyR) > Mode(freq) [1] "1" You have a single modal value (1). If there were at most

[R] find multiple mode

2020-03-15 Thread Yuan Chun Ding
Hi R users, I want to find multiple modes (10, 8, 149) for the following vector. freq =1,2,5,5 10,4,4,8,1,1,8,8,2,4,3,1,2,1,1 138 149 14,1,1; any suggestion? Thank you, Ding --

Re: [R] Find the max entry in column 2 - that satisfies a condition given a fixed entry in column 1

2019-06-22 Thread Richard O'Keefe
I have read your message four times in the last couple of days, but I still have very little idea what you want. Let's try some things I've gleaned. You have a matrix with 9 rows and 2 columns, and there is a 2 somewhere in column 1. > m <- matrix(1:18, nrow=9, ncol=2) > m[c(4,7,8),1] <- 2 > m

Re: [R] Find the max entry in column 2 - that satisfies a condition given a fixed entry in column 1

2019-06-21 Thread Rui Barradas
Hello, Thinking again, if all you want is vector b the following function fun2 will do it without having to create plain. Less memory and (much) faster. fun2 <- function(X, val){ u <- sort(unique(X)) n <- length(u) b <- numeric(n^2) b[n*(n - 1) + match(val, u)] <- u[n] b }

Re: [R] Find the max entry in column 2 - that satisfies a condition given a fixed entry in column 1

2019-06-20 Thread Rui Barradas
Hello, Inline. Às 10:15 de 20/06/19, Vangelis Litos escreveu: I am using R and I created based on a vector x, a grid (named: plain) - where zero is included. This gives me a 9x2 ``matrix''. x_t = cbind(c(1),c(2)); x = t(x_t); This code works but there are several issues with it. 1) c(1)

Re: [R] Find the max entry in column 2 - that satisfies a condition given a fixed entry in column 1

2019-06-20 Thread Bert Gunter
"Can anybody help me with this?" Probably not. Your explanation is as clear as mud -- to me anyway. Showing us the actual data or code of a simple example, what you want to do and what you have tried, and what you would like to get would likely help (assuming it's not just me being dense, always

[R] Find the max entry in column 2 - that satisfies a condition given a fixed entry in column 1

2019-06-20 Thread Vangelis Litos
I am using R and I created based on a vector x, a grid (named: plain) - where zero is included. This gives me a 9x2 ``matrix''. > x_t = cbind(c(1),c(2)); > x = t(x_t); > plain = expand.grid (sort (unique (c (0, x))), sort (unique (c (0, x; My aim is to focus on column 1 and take i.e the

Re: [R] find the permutation function of a sorting

2018-05-23 Thread John
Thanks, David, Rui and Jeff!!! The function order works much better. I should have used an example where the permutation and its inverse are not identical: > i <- order(c("B", "C", "A")) > i [1] 3 1 2 > c("D","E", "F")[i] [1] "F" "D" "E" > c("D","E", "F")[order(i)] [1] "E" "F" "D" 2018-05-23

Re: [R] find the permutation function of a sorting

2018-05-23 Thread Rui Barradas
Hello, Like David said, what you are trying to do with sort() can be done with order() in a much easier way. First, your code x <- sort(c("bc","ac","dd"), index.return=TRUE) Now, with function order() i <- order(c("bc", "ac", "dd")) y <- c("D","E", "F")[i] y #[1] "E" "D" "F" # This

Re: [R] find the permutation function of a sorting

2018-05-22 Thread David Winsemius
> On May 22, 2018, at 11:37 PM, John wrote: > > > > sort(c("bc","ac","dd"), index.return=TRUE) > $x > [1] "ac" "bc" "dd" > > $ix > [1] 2 1 3 > > > We have the permutation, namely 1-->2, 2-->1, 3-->3. > How can I apply the permutation function to a new set > c("D","E",

Re: [R] find the permutation function of a sorting

2018-05-22 Thread Jeff Newmiller
Perhaps the question was "what is indexing"? On May 23, 2018 5:06:39 AM GMT+02:00, David Winsemius wrote: > > >> On May 22, 2018, at 10:57 PM, John wrote: >> >> Thanks, David. >> I got the answer from the web. >> Is there any easy way to permute a

Re: [R] find the permutation function of a sorting

2018-05-22 Thread John
> sort(c("bc","ac","dd"), index.return=TRUE) $x [1] "ac" "bc" "dd" $ix [1] 2 1 3 We have the permutation, namely 1-->2, 2-->1, 3-->3. How can I apply the permutation function to a new set c("D","E", "F")? so that the result is c("E","D", "F"). 2018-05-23 11:06 GMT+08:00 David Winsemius

Re: [R] find the permutation function of a sorting

2018-05-22 Thread David Winsemius
> On May 22, 2018, at 10:57 PM, John wrote: > > Thanks, David. > I got the answer from the web. > Is there any easy way to permute a set (e.g., a set of characters) by the > permutation it returns? Thanks, > > > > x <- c(10,7,4,3,8,2) > > sort(x, index.return=TRUE) > $x

Re: [R] find the permutation function of a sorting

2018-05-22 Thread John
Thanks, David. I got the answer from the web. Is there any easy way to permute a set (e.g., a set of characters) by the permutation it returns? Thanks, > x <- c(10,7,4,3,8,2) > sort(x, index.return=TRUE) $x [1] 2 3 4 7 8 10 $ix [1] 6 4 3 2 5 1 2018-05-23 10:49 GMT+08:00 David Winsemius

Re: [R] find the permutation function of a sorting

2018-05-22 Thread David Winsemius
> On May 22, 2018, at 10:06 PM, John wrote: > > Hi, > > Is there any way to find the permutation function of the sorting and to > apply the function (or its inverse) elsewhere? > > For example, the following permutation function from the sorting in the > matrix form is

[R] find the permutation function of a sorting

2018-05-22 Thread John
Hi, Is there any way to find the permutation function of the sorting and to apply the function (or its inverse) elsewhere? For example, the following permutation function from the sorting in the matrix form is c(1,2,3), c(2,1,3) > sort(c("bc","ac","dd")) [1] "ac" "bc" "dd" I try to

[R] find common regions between two kinds of tests

2018-05-15 Thread Ding, Yuan Chun
Dear R community, For 100 sites at human chromosomes, I ran two tests, one is to consider an experiment measurement as a continuous variable, so doing multiple regression; the other is to compare top 25% samples to bottom 25% samples based on values of the measured variable, so categorical

Re: [R] find unique and summerize

2018-02-04 Thread Val
Thank you so much Rui! On Sun, Feb 4, 2018 at 12:20 AM, Rui Barradas wrote: > Hello, > > Please always cc the list. > > As for the question, I believe the following does it. > > a <- strsplit(mydata$ID, "[[:alpha:]]+") > b <- strsplit(mydata$ID, "[[:digit:]]+") > > a <-

Re: [R] find unique and summerize

2018-02-03 Thread Rui Barradas
Hello, As for the first question, instead of writing a xlsx file, maybe it is easier to write a csv file and then open it with Excel. tbl2 <- addmargins(tbl1) write.csv(tbl2, "tt1.csv") As for the second question, the following does it. inx <- apply(tbl1, 1, function(x) all(x != 0)) tbl1b

Re: [R] find unique and summerize

2018-02-03 Thread Val
Thank you so much Rui. 1. How do I export this table to excel file? I used this tbl1 <- table(Country, IDNum) tbl2=addmargins(tbl1) write.xlsx(tbl2,"tt1.xlsx"),sheetName="summary", row.names=FALSE) The above did not give me that table. 2. I want select those unique Ids that do

Re: [R] find unique and summerize

2018-02-02 Thread Rui Barradas
Hello, Thanks for the reproducible example. See if the following does what you want. IDNum <- sub("^(\\d+).*", "\\1", mydata$ID) Country <- sub("^\\d+(.*)", "\\1", mydata$ID) tbl1 <- table(Country, IDNum) addmargins(tbl1) tbl2 <- xtabs(Y ~ Country + IDNum, mydata) addmargins(tbl2) Hope this

[R] find unique and summerize

2018-02-02 Thread Val
Hi all, I have a data set need to be summarized by unique ID (count and sum of a variable) A unique individual ID (country name Abbreviation followed by an integer numbers) may have observation in several countries. Then the ID was changed by adding the country code as a prefix and new ID

Re: [R] Find maxima of a function

2017-08-26 Thread David Winsemius
> On Aug 26, 2017, at 12:13 PM, Ismail SEZEN wrote: > > >> On 26 Aug 2017, at 16:39, niharika singhal >> wrote: >> >> Hi, >> >> Thanks for your mail, and time >> >> It is not working for some arguments, when mean value is like >6. >>

Re: [R] Find maxima of a function

2017-08-26 Thread Ismail SEZEN
> On 26 Aug 2017, at 16:39, niharika singhal > wrote: > > Hi, > > Thanks for your mail, and time > > It is not working for some arguments, when mean value is like >6. > > > case > > mc0 <- c(0.0886,0.1744455,0.1379778,0.1209769,0.1573065,0. >

Re: [R] Find maxima of a function

2017-08-26 Thread Ismail SEZEN
> On 26 Aug 2017, at 14:18, Ulrik Stervbo wrote: > > Please keep the list in cc. > > Sorry, it didn't work as expected. Maybe someone else have an appropriate > solution. > > Best, > Ulrik > > On Sa., 26. Aug. 2017, 12:57 niharika singhal

Re: [R] Find maxima of a function

2017-08-26 Thread Ulrik Stervbo
Please keep the list in cc. Sorry, it didn't work as expected. Maybe someone else have an appropriate solution. Best, Ulrik On Sa., 26. Aug. 2017, 12:57 niharika singhal wrote: > Hi > > Thanks for you mail, > I really appreciate your time on my problem > > I

Re: [R] Find maxima of a function

2017-08-26 Thread Ulrik Stervbo
Hi, I once found this somewhere on stackoverflow: values <- rnorm(20, mean = c(2.15,2.0,2.9), sd = c(0.1,0.1,0.1)) v_dens <- density(values) v_dens_y <- v_dens$y r <- rle(v_dens_y) # These functions ignore the extremes if they are the first or last point maxima_index <- which(rep(x =

[R] Find maxima of a function

2017-08-26 Thread niharika singhal
I have a Gaussian mixture model with some parameters mean=(506.8644,672.8448,829.902) sigma=(61.02859,9.149168,74.84682) c=(0.1241933, 0.6329082, 0.2428986) And the plot look something like below.[image: enter image description here] Also, if I change my

Re: [R] find similar words in text

2017-08-03 Thread Patrick Casimir
Steipe <boris.ste...@utoronto.ca> Sent: Thursday, August 3, 2017 6:40:09 PM To: Riaan Van Der Walt Cc: R lists Subject: Re: [R] find similar words in text Please keep messages on the list so others can pitch in. _Which_ words do you want to consider identical for the purpose of frequency count? _

Re: [R] find similar words in text

2017-08-03 Thread Boris Steipe
Please keep messages on the list so others can pitch in. _Which_ words do you want to consider identical for the purpose of frequency count? _What_ do you want to plot? B. > On Aug 3, 2017, at 4:36 PM, Riaan Van Der Walt > wrote: > > Hallo Boris, > I've

Re: [R] find similar words in text

2017-08-03 Thread Bert Gunter
You really need to spend some time learning R if you wish to use R. See ?grep and note the "value" argument. So you want: whales.v <- grep(*^whal.*", moby.word.v,value = TRUE) -- Bert On Thu, Aug 3, 2017 at 5:14 AM, Riaan Van Der Walt wrote: > I received this

[R] find similar words in text

2017-08-03 Thread Riaan Van Der Walt
I received this from Matt Jockers and it worked! I missed something. How can I now see(display) this list? Hi Riann, There are a couple of ways that you could do this. . . the best approach would probably be to use *grep* instead of *which*, but let me show you both ways. On page 30, replace

  1   2   3   4   5   6   >