Re: [R] data frame manipulation change elements meeting criteria

2010-05-27 Thread Joris Meys
, something like : if(trade$Trade.Status==DEL)switch(.) I would like to avoid the loop . From: Joris Meys [mailto:jorism...@gmail.com] Sent: Wednesday, May 26, 2010 9:15 PM To: arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation change elements meeting

Re: [R] data frame manipulation change elements meeting criteria

2010-05-27 Thread arnaud Gaboury
Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation change elements meeting criteria see ?switch X- rep(c(Buy,Sell,something else),each=5) Y- rep(c(DEL,INS,DEL),5) new.vect - X for (i in which(Y==DEL)){     new.vect[i]-switch(   EXPR = X[i],   Sell=Buy,   Buy

Re: [R] data frame manipulation change elements meeting criteria

2010-05-27 Thread arnaud Gaboury
..sum. NULL That's certainly not what I want. From: Joris Meys [mailto:jorism...@gmail.com] Sent: Thursday, May 27, 2010 8:43 AM To: arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation change elements meeting criteria The loop is due to the switch statement

Re: [R] data frame manipulation change elements meeting criteria

2010-05-27 Thread Joris Meys
NULL $Net.Charges..sum. NULL That's certainly not what I want. From: Joris Meys [mailto:jorism...@gmail.com] Sent: Thursday, May 27, 2010 8:43 AM To: arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation change elements meeting criteria The loop is due

Re: [R] data frame manipulation change elements meeting criteria

2010-05-27 Thread Joris Meys
want !! From: Joris Meys [mailto:jorism...@gmail.com] Sent: Thursday, May 27, 2010 10:38 AM To: arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation change elements meeting criteria Off course. You put in a matrix to sapply, but sapply is for vectors. You want

Re: [R] data frame manipulation change elements meeting criteria

2010-05-27 Thread arnaud Gaboury
] Buy $Price NULL $Net.Charges..sum. NULL That's certainly not what I want. From: Joris Meys [mailto:jorism...@gmail.com] Sent: Thursday, May 27, 2010 8:43 AM To: arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation change elements meeting criteria The loop is due

Re: [R] data frame manipulation change elements meeting criteria

2010-05-27 Thread arnaud Gaboury
To: arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation change elements meeting criteria Off course. You put in a matrix to sapply, but sapply is for vectors. You want to apply the switch command on every entry of the vector trades$Buy.Sell..Cleared for which trades

[R] data frame manipulation change elements meeting criteria

2010-05-26 Thread arnaud Gaboury
Dear group, Here is my df : trade - structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name = c(SUGAR NO.11, CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10, Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume = c(1L, 2L, 1L), Price = c(15.2500, 368., 368.5000),

Re: [R] data frame manipulation change elements meeting criteria

2010-05-26 Thread Joris Meys
see ?switch X- rep(c(Buy,Sell,something else),each=5) Y- rep(c(DEL,INS,DEL),5) new.vect - X for (i in which(Y==DEL)){ new.vect[i]-switch( EXPR = X[i], Sell=Buy, Buy=Sell, X[i]) } cbind(new.vect,X,Y) On Wed, May 26, 2010 at 7:43 PM, arnaud Gaboury