Re: [R] Selecting elements

2021-08-25 Thread Jim Lemon
table(data.o$Var.1[1:6]) #scheme 3 >> > >> > A B C D >> > 2 1 2 1 >> > >> > > table(data.o$Var.1[1:7]) # scheme1 >> > A B C D >> > 2 1 2 2 >> > >> > > table(data.o$Var.1[1:8]) # no such scheme, so scheme 1 is chos

Re: [R] Selecting elements

2021-08-25 Thread Silvano Cesar da Costa
Var.1[1:8]) # no such scheme, so scheme 1 is chosen one > > A B C D > > 2 1 2 3 > > > > #Now you need to select values based on scheme 1. > > # 3A - 3B - 2C - 2D > > > > sss <- split(Order, Order$Var.1) > > selection <- c(3,3,2,2) > > re

Re: [R] Selecting elements

2021-08-24 Thread Jim Lemon
on scheme 1. > # 3A - 3B - 2C - 2D > > sss <- split(Order, Order$Var.1) > selection <- c(3,3,2,2) > result <- vector("list", 4) > > #I would use loop > > for(i in 1:4) { > result[[i]] <- sss[[i]][1:selection[i],] > } > > Maybe someone com

Re: [R] Selecting elements

2021-08-24 Thread PIKAL Petr
ult[[i]] <- sss[[i]][1:selection[i],] } Maybe someone come with other ingenious solution. Cheers Petr From: Silvano Cesar da Costa Sent: Monday, August 23, 2021 7:54 PM To: PIKAL Petr Cc: r-help@r-project.org Subject: Re: [R] Selecting elements Hi, I apologize for the confusion. I will t

Re: [R] Selecting elements

2021-08-23 Thread Silvano Cesar da Costa
gt; $D > [1] 39 77 114 141 166 189 209 223 229 232 > > Highest value is in D so either 3A - 3B - 2C - 2D or 3A - 3B - 2C - 2D > should be appropriate. And here I am again lost as both sets are same. > Maybe you need to reconsider your statements. > > Cheers > Petr > >

Re: [R] Selecting elements

2021-08-23 Thread PIKAL Petr
alue is in D so either 3A - 3B - 2C - 2D or 3A - 3B - 2C - 2D should be appropriate. And here I am again lost as both sets are same. Maybe you need to reconsider your statements. Cheers Petr From: Silvano Cesar da Costa Sent: Friday, August 20, 2021 9:28 PM To: PIKAL Petr Cc: r-help@r-project.

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] 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] 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] Selecting elements

2021-08-19 Thread PIKAL Petr
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, replace=FALSE) data = data.frame(Var.1, Var.2) What should be the desired outcome? You can sort data <- data[order

Re: [R] Selecting elements in lists with a row condition

2014-02-04 Thread David Winsemius
On Feb 4, 2014, at 11:54 AM, Francesca Pancotto wrote: > Hello A. k. > thanks for the suggestion. > > I tried this but it does not work. I probably use it in the wrong way. > This is what it tells me, > > > do.call(rbind,lapply(bank.list,function(x) x[x[,"p_made"]==406,])) > > Errore in mat

Re: [R] Selecting elements in lists with a row condition

2014-02-04 Thread Jim Lemon
On 02/05/2014 06:54 AM, Francesca Pancotto wrote: Hello A. k. thanks for the suggestion. I tried this but it does not work. I probably use it in the wrong way. This is what it tells me, do.call(rbind,lapply(bank.list,function(x) x[x[,"p_made"]==406,])) Errore in match.names(clabs, names(xi)

Re: [R] Selecting elements in lists with a row condition

2014-02-04 Thread arun
Hi, Looks like the colnames of list elements are not the same. For e.g. lst1 <- list(structure(list(bankname = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "CIB", class = "factor"), date = structure(c(1L, 2L, 3L, 1L, 2L, 3L), .Label = c("10/02/06", "10/23/06", "11/22/06" ), class = "factor"), px

Re: [R] Selecting elements in lists with a row condition

2014-02-04 Thread Francesca Pancotto
Hello A. k. thanks for the suggestion. I tried this but it does not work. I probably use it in the wrong way. This is what it tells me, do.call(rbind,lapply(bank.list,function(x) x[x[,"p_made"]==406,])) Errore in match.names(clabs, names(xi)) : names do not match previous names What am I

Re: [R] Selecting elements in lists with a row condition

2014-02-04 Thread arun
Hi, Try: If `lst1` is the list: do.call(rbind,lapply(lst1,function(x) x[x[,"p_made"]==406,])) A.K. On Tuesday, February 4, 2014 8:53 AM, Francesca wrote: Dear Contributors sorry but the message was sent involuntary. I am asking some advice on how to solve the following problem. I have a list

Re: [R] Selecting elements in lists with a row condition

2014-02-04 Thread Francesca
Dear Contributors sorry but the message was sent involuntary. I am asking some advice on how to solve the following problem. I have a list composed of 78 elements, each of which is a matrix of factors and numbers, similar to the following bank_name date px_last_CIB Q.Yp_made p_for 1

Re: [R] Selecting elements from all items in a list

2012-02-14 Thread geotheory
Yes the lapply function sorted it out. Thanks for the advice. -- View this message in context: http://r.789695.n4.nabble.com/Selecting-elements-from-all-items-in-a-list-tp4387045p4387505.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] Selecting elements from all items in a list

2012-02-14 Thread David Winsemius
On Feb 14, 2012, at 8:44 AM, geotheory wrote: Basic question (if you know the answer)... I am dealing with a list of commonly-formatted sub-lists, for example: l <- list("") l[[1]] <- c("A1","A2","A3") l[[2]] <- c("B1","B2","B3") l[[3]] <- c("C1","B2","B3") Lets say I need to extract every

Re: [R] Selecting elements from all items in a list

2012-02-14 Thread Dimitris Rizopoulos
How about: l <- list("") l[[1]] <- c("A1","A2","A3") l[[2]] <- c("B1","B2","B3") l[[3]] <- c("C1","B2","B3") lapply(l, "[[", 2) or sapply(l, "[[", 2) I hope it helps. Best, Dimitris On 2/14/2012 2:44 PM, geotheory wrote: Basic question (if you know the answer)... I am dealing with a li

Re: [R] selecting elements in vector

2011-01-14 Thread Henrique Dallazuanna
Try this: !list %in% c("aa", "bb") On Fri, Jan 14, 2011 at 10:19 AM, A M Lavezzi wrote: > Hi everybody, > > I have the following problem. I have a vector containing character > elements, > such as: > > list = c("aa","bb","cc","dd","ee") > > I want to create an index which identifies the element

Re: [R] selecting elements in vector

2011-01-14 Thread A M Lavezzi
it works! thank you so much Mario On Fri, Jan 14, 2011 at 1:29 PM, Henrique Dallazuanna wrote: > Try this: > > !list %in% c("aa", "bb") > > On Fri, Jan 14, 2011 at 10:19 AM, A M Lavezzi wrote: > >> Hi everybody, >> >> I have the following problem. I have a vector containing character >> element

Re: [R] selecting elements in vector

2011-01-14 Thread Henrique Dallazuanna
Try this: !list %in% c("aa", "bb") On Fri, Jan 14, 2011 at 10:19 AM, A M Lavezzi wrote: > Hi everybody, > > I have the following problem. I have a vector containing character > elements, > such as: > > list = c("aa","bb","cc","dd","ee") > > I want to create an index which identifies the element

Re: [R] Selecting elements from a vector (a simple question with weird results)

2009-03-29 Thread andrew
aa[order(aa)] is the same as sort, although sort is much quicker and has lower memory requirements: > aa <- rnorm(1000) > all(aa[order(aa)] == sort(aa)) [1] TRUE > system.time(sort(aa)) user system elapsed 7.270.088.25 > system.time(aa[order(aa)]) user system elapsed 29.58

Re: [R] Selecting elements from a vector (a simple question with weird results)

2009-03-28 Thread Tal Galili
Yes Johannes - That helped, thank you. On Sat, Mar 28, 2009 at 11:50 PM, Johannes Huesing wrote: > Tal Galili [Sat, Mar 28, 2009 at 06:48:36PM CET]: > > Hello people. > > > > I wish to reorder a simple vector of numbers by another vector of the > order > > (and then do the same, but with a da

Re: [R] Selecting elements from a vector (a simple question with weird results)

2009-03-28 Thread Johannes Huesing
Tal Galili [Sat, Mar 28, 2009 at 06:48:36PM CET]: > Hello people. > > I wish to reorder a simple vector of numbers by another vector of the order > (and then do the same, but with a data frame rows) > > I try this (which doesn't work) : > > aa <- c(3, 1 ,2 ) > > aa[aa] > [1] 2 3 1 To my mind, i

Re: [R] Selecting elements from a vector (a simple question with weird results)

2009-03-28 Thread Tal Galili
Thanks Jorge , I mistakingly (and foolishly) confused a vector of ranking, to a vector of ordering that ranked vector... Patrick Burns explained to me that I was looking for: aa[order(aa)] df[order(df[,1]), ] Sorry, Tal On Sat, Mar 28, 2009 at 9:08 PM, Jorge Ivan Velez wrote: > > Dear Tal,

Re: [R] Selecting elements from a vector (a simple question with weird results)

2009-03-28 Thread Jorge Ivan Velez
Dear Tal, It works as it should. In this code: # Data aa <- c(3, 1 ,2 ) aa [1] 3 1 2 aa[aa] [1] 2 3 1 you are telling R to do the following: take the vector aa and select the elements aa (in R language that is aa[aa]). If you look carefully, the third element of aa is 2, the first is 3 and the

Re: [R] Selecting elements from a vector (a simple question with weird results)

2009-03-28 Thread Tal Galili
Thanks Patrick, Sorry to have missed that! Tal On Sat, Mar 28, 2009 at 9:01 PM, Patrick Burns wrote: > I presume you are looking for: > > aa[order(aa)] > > and > > df[order(df[,1]), ] > > > Patrick Burns > patr...@burns-stat.com > +44 (0)20 8525 0696 > http://www.burns-stat.com > (home of

Re: [R] Selecting elements from a vector (a simple question with weird results)

2009-03-28 Thread Philipp Pagel
> I wish to reorder a simple vector of numbers by another vector of the order > (and then do the same, but with a data frame rows) > > I try this (which doesn't work) : > > aa <- c(3, 1 ,2 ) > > aa[aa] > [1] 2 3 1 > > The same won't work if I try to order a data frame: > > data.frame(matrix(c(3,1

Re: [R] Selecting elements in vector

2008-03-14 Thread Rainer M Krug
Thanks - that is exactly what I was looking for Rainer On Fri, Mar 14, 2008 at 1:10 PM, Henrique Dallazuanna <[EMAIL PROTECTED]> wrote: > Try this: > > x[x %in% y] > > > > On 14/03/2008, Rainer M Krug <[EMAIL PROTECTED]> wrote: > > Hi > > > > Consider the following code > > > > > x <- re

Re: [R] Selecting elements in vector

2008-03-14 Thread Gabor Csardi
Use %in%: x [ x %in% y ] G. On Fri, Mar 14, 2008 at 12:37:45PM +0200, Rainer M Krug wrote: > Hi > > Consider the following code > > > x <- rep(1:13, 13) > > > y <- 1:3 > > I want to select all elements in x which are equal to 1, 2 or 3. > > I know that I could use > > > sel <- x==y[1] | x=

Re: [R] Selecting elements in vector

2008-03-14 Thread Henrique Dallazuanna
Try this: x[x %in% y] On 14/03/2008, Rainer M Krug <[EMAIL PROTECTED]> wrote: > Hi > > Consider the following code > > > x <- rep(1:13, 13) > > > y <- 1:3 > > I want to select all elements in x which are equal to 1, 2 or 3. > > I know that I could use > > > sel <- x==y[1] | x==y[2] | x==y[3