Re: [R] conditional statement to replace values in dataframe with NA

2012-06-07 Thread arun
  1  2   B 6  1  3   B A.K. - Original Message - From: Daisy Englert Duursma To: "r-help@R-project.org" Cc: Sent: Wednesday, June 6, 2012 11:58 PM Subject: [R] conditional statement to replace values in dataframe with NA Hello and thanks for helping. #some data L3 <- LE

Re: [R] conditional statement to replace values in dataframe with NA

2012-06-07 Thread peter dalgaard
On Jun 7, 2012, at 07:28 , Bert Gunter wrote: > Actually, recycling makes the rep(NA,2) business unnecessary. Simply: > > dat1[dat1$x==1 & dat1$y==1,1:2] <- rep(NA,2) > > ##or > > with(dat1,{dat1[x==1 & y==1,1:2] <- NA;dat1}) > > will do it. > Or, use the assignment form of is.na: cond <-

Re: [R] conditional statement to replace values in dataframe with NA

2012-06-06 Thread Daisy Englert Duursma
Thanks, problem solved. On Thu, Jun 7, 2012 at 1:58 PM, Daisy Englert Duursma wrote: > Hello and thanks for helping. > > #some data > L3 <- LETTERS[1:3] > dat1 <- data.frame(cbind(x=1, y=rep(1:3,2), fac=sample(L3, 6, replace=TRUE))) > > > #When x==1 and y==1 I want to replace the 1 values with NA

Re: [R] conditional statement to replace values in dataframe with NA

2012-06-06 Thread Bert Gunter
Actually, recycling makes the rep(NA,2) business unnecessary. Simply: dat1[dat1$x==1 & dat1$y==1,1:2] <- rep(NA,2) ##or with(dat1,{dat1[x==1 & y==1,1:2] <- NA;dat1}) will do it. -- Bert On Wed, Jun 6, 2012 at 10:21 PM, Bert Gunter wrote: > Have you read "An Intro to R?" If not,please do so

Re: [R] conditional statement to replace values in dataframe with NA

2012-06-06 Thread Bert Gunter
Have you read "An Intro to R?" If not,please do so before posting further. The way you are going about things makes me think you haven't, but ... This **is** a slightly tricky application of indexing, if I understand you correctly. Here are two essentially identical ways to do it, but the second i

[R] conditional statement to replace values in dataframe with NA

2012-06-06 Thread Daisy Englert Duursma
Hello and thanks for helping. #some data L3 <- LETTERS[1:3] dat1 <- data.frame(cbind(x=1, y=rep(1:3,2), fac=sample(L3, 6, replace=TRUE))) #When x==1 and y==1 I want to replace the 1 values with NA #I can select the rows I want: dat2<-subset(dat1,x==1 & y==1) #replace the 1 with NA dat2$x<-rep(N

Re: [R] Conditional statement

2009-11-16 Thread David Winsemius
On Nov 16, 2009, at 7:43 AM, Rafael Moral wrote: Dear useRs, I wrote a function that simulates a stochastic model in discrete time. The problem is that the stochastic parameters should not be negative and sometimes they happen to be. How can I conditionate it to when it draws a negative numb

Re: [R] Conditional statement

2009-11-16 Thread jim holtman
Generate the numbers, test for zero and then set negatives to zero: > set.seed(1) > x <- rnorm(100,5,3) > sum(x<0) [1] 3 > x[x<0] <- 0 > sum(x<0) [1] 0 > On Mon, Nov 16, 2009 at 7:43 AM, Rafael Moral wrote: > Dear useRs, > > I wrote a function that simulates a stochastic model in discrete time.

[R] Conditional statement

2009-11-16 Thread Rafael Moral
Dear useRs, I wrote a function that simulates a stochastic model in discrete time. The problem is that the stochastic parameters should not be negative and sometimes they happen to be. How can I conditionate it to when it draws a negative number, it transforms into zero in that time step? Here

Re: [R] Conditional statement used in sapply()

2008-08-13 Thread Erik Iverson
Hello - Altaweel, Mark R. wrote: Hi, I have data stored in a list that I would like to aggregate and perform some basic stats. However, I would like to apply conditional statements so that not all the data are used. Basically, I want to get a specific variable, do some basic functions (such as

Re: [R] Conditional statement used in sapply()

2008-08-13 Thread Altaweel, Mark R.
E: [R] Conditional statement used in sapply() > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On Behalf Of Altaweel, Mark R. > Sent: Wednesday, August 13, 2008 3:03 PM > To: r-help@r-project.org > Subject: [R] Conditional statement used in sapply() &g

Re: [R] Conditional statement used in sapply()

2008-08-13 Thread Steven McKinney
> -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On Behalf Of Altaweel, Mark R. > Sent: Wednesday, August 13, 2008 3:03 PM > To: r-help@r-project.org > Subject: [R] Conditional statement used in sapply() > > Hi, > > I have data

Re: [R] Conditional statement used in sapply()

2008-08-13 Thread Ling, Gary (Electronic Trading)
: Wednesday, August 13, 2008 6:03 PM To: r-help@r-project.org Subject: [R] Conditional statement used in sapply() Hi, I have data stored in a list that I would like to aggregate and perform some basic stats. However, I would like to apply conditional statements so that not all the data are used. Basica

[R] Conditional statement used in sapply()

2008-08-13 Thread Altaweel, Mark R.
Hi, I have data stored in a list that I would like to aggregate and perform some basic stats. However, I would like to apply conditional statements so that not all the data are used. Basically, I want to get a specific variable, do some basic functions (such as a mean), but only get the data i