Re: [R] Ifelse statements and combining columns

2017-07-25 Thread PIKAL Petr
ilto:r-help-boun...@r-project.org] On Behalf Of Kirsten > Morehouse > Sent: Monday, July 24, 2017 2:24 PM > To: R-help <r-help@r-project.org> > Subject: [R] Ifelse statements and combining columns > > Hi everyone, > > I'm having some trouble with my ifelse stateme

Re: [R] Ifelse statements and combining columns

2017-07-24 Thread Koustav Pal
That ifelse statement is a mess, it is missing brackets, comma separators between arguments and & or | between conditions. The bracket error points towards the invalid bracket you had in the second ifelse since it expects and yes and a no argument alongside conditions. ifelse(test = (dat$cond ==

Re: [R] Ifelse statements and combining columns

2017-07-24 Thread Duncan Murdoch
On 24/07/2017 8:57 AM, Jeff Newmiller wrote: Not a reproducible example, so a bit of guessing here, but a) don't try to assign results to variables inside the ifelse. That is, remove all the single-equals signs and "test" variables. If you really need to conditionally assign variables then

Re: [R] Ifelse statements and combining columns

2017-07-24 Thread Jeff Newmiller
Not a reproducible example, so a bit of guessing here, but a) don't try to assign results to variables inside the ifelse. That is, remove all the single-equals signs and "test" variables. If you really need to conditionally assign variables then use "if"... but chances are good you don't need

Re: [R] Ifelse statements and combining columns

2017-07-24 Thread Rui Barradas
Hello, Your ifelse statement is a mess. I cannot make sense of it. Let me try to explain where I've lost it. dat$cond <- ifelse(test = dat$cond == "cond1" This is already very bad, do you mean dat$cond == "cond1" ? Maybe you mean that condition OR the others below, but then there's one '|'

[R] Ifelse statements and combining columns

2017-07-24 Thread Kirsten Morehouse
Hi everyone, I'm having some trouble with my ifelse statements. I'm trying to put 12 conditions within 3 groups. Here is the code I have so far: dat$cond <- ifelse(test = dat$cond == "cond1" | dat$cond == "cond2" | dat$cond == "cond3" dat$cond == "cond4" yes = "Uniform"

Re: [R] ifelse for creating discriminating variable based on two conditions

2016-10-14 Thread PIKAL Petr
o: Andreas Nord <andreas.n...@biol.lu.se> > Cc: r-help@r-project.org > Subject: Re: [R] ifelse for creating discriminating variable based on two > conditions > > Hi Andreas, > Try this: > > fruit_2sds<-by(data2$molecule,data2$fruit,sd)*2 > data2$newcol<-ifelse(data2$

Re: [R] ifelse for creating discriminating variable based on two conditions

2016-10-14 Thread Jim Lemon
Hi Andreas, Try this: fruit_2sds<-by(data2$molecule,data2$fruit,sd)*2 data2$newcol<-ifelse(data2$molecule>fruit_2sds[data2$fruit],1,0) or even just: data$newcol<-as.numeric(data2$molecule>fruit_2sds[data2$fruit]) Jim On Fri, Oct 14, 2016 at 5:17 PM, Andreas Nord

[R] ifelse for creating discriminating variable based on two conditions

2016-10-14 Thread Andreas Nord
Dear list, Apologies for a likely naive question. I am trying to create a discriminating dummy variable using 'ifelse' based on conditions in two variables. Specifically, I want to assign levels in a new factor as '0' or '1' based on a user-defined cut off. I.e. something similar to:

Re: [R] ifelse and vs

2015-05-13 Thread Jim Lemon
Hi nusrat, The ifelse function returns the number of values that result from the logical expression in the first argument. If you use , you get one logical value. If you use you get logical values for the number of conditionals that you specify. For example: 1:10 0 1:10 11:20 [1] TRUE 1:10

Re: [R] ifelse and vs

2015-05-12 Thread nusrat ullah
Ip, g ftehgytreehjjjijiputv Sent from my iPadgypyrrytutytytfedewaqyŷiijj __ 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] Ifelse statement on a factor level data frame

2014-09-28 Thread Patrick Burns
I believe you are in Circle 8.2.7 of The R Inferno. http://www.burns-stat.com/documents/books/the-r-inferno/ Pat On 28/09/2014 05:49, Kate Ignatius wrote: Quick question: I am running the following code on some variables that are factors: dbpmn$IID1new - ifelse(as.character(dbpmn[,2]) ==

Re: [R] Ifelse statement on a factor level data frame

2014-09-28 Thread Kate Ignatius
Strange that, I did put everything with as.character but all I got was the same... class of dbpmn[,2]) = factor class of dbpmn[,21] = factor class of dbpmn[,20] = data.frame This has to be a problem ??? I can put reproducible output here but not sure if this going to of help here. I think

Re: [R] Ifelse statement on a factor level data frame

2014-09-28 Thread Bert Gunter
Inline. Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. Clifford Stoll On Sun, Sep 28, 2014 at 6:38 AM, Kate Ignatius kate.ignat...@gmail.com wrote: Strange that, I did put

Re: [R] Ifelse statement on a factor level data frame

2014-09-28 Thread Kate Ignatius
Apologies - you're right. Missed it in the pdf. K. On Sun, Sep 28, 2014 at 10:22 AM, Bert Gunter gunter.ber...@gene.com wrote: Inline. Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not

Re: [R] Ifelse statement on a factor level data frame

2014-09-28 Thread William Dunlap
ifelse() often has problems constructing the right type of return value. if you want to keep the data as a factor (with its existing levels) use x[condition] - value instead of ifelse(condition, value, x). E.g., x - factor(c(Large,Small,Small,XLarge), levels=c(Small,Med,Large,XLarge)) x

[R] Ifelse statement on a factor level data frame

2014-09-27 Thread Kate Ignatius
Quick question: I am running the following code on some variables that are factors: dbpmn$IID1new - ifelse(as.character(dbpmn[,2]) == as.character(dbpmn[,(21)]), dbpmn[,20], '') Instead of returning some value it gives me this: c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)) Playing around

Re: [R] Ifelse statement on a factor level data frame

2014-09-27 Thread Jeff Newmiller
Not reproducible, ball in your court. However, in the meantime, my suggestion is to not do that. Convert to character before you alter the factor, then convert back when you are done. --- Jeff Newmiller

Re: [R] Ifelse statement on a factor level data frame

2014-09-27 Thread Jim Lemon
On Sun, 28 Sep 2014 12:49:41 AM Kate Ignatius wrote: Quick question: I am running the following code on some variables that are factors: dbpmn$IID1new - ifelse(as.character(dbpmn[,2]) == as.character(dbpmn[,(21)]), dbpmn[,20], '') Instead of returning some value it gives me this:

[R] ifelse...

2014-01-16 Thread Tim Smith
Hi, Sorry for the newbie question! My code: x - 'a' ifelse(x == 'a',y - 1, y - 2) print(y) Shouldn't this assign a value of 1? When I execute this I get: x - 'a' ifelse(x == 'a',y - 1, y - 2) [1] 1 print(y) [1] 2 Am I doing something really daft??? thanks! sessionInfo() R version

Re: [R] ifelse...

2014-01-16 Thread ONKELINX, Thierry
januari 2014 14:32 Aan: r Onderwerp: [R] ifelse... Hi, Sorry for the newbie question! My code: x - 'a' ifelse(x == 'a',y - 1, y - 2) print(y) Shouldn't this assign a value of 1? When I execute this I get: x - 'a' ifelse(x == 'a',y - 1, y - 2) [1] 1 print(y) [1] 2 Am I doing something really

Re: [R] ifelse...

2014-01-16 Thread Duncan Murdoch
On 16/01/2014 8:46 AM, ONKELINX, Thierry wrote: You want y - ifelse(x == 'a', 1, 2) or use if, rather than ifelse, i.e. if (x == 'a') { y - 1 } else { y - 2 } ifelse() is mainly used when you want to work with whole vectors of decisions, e.g. x - 1:10 ifelse(x 5, 1, 0) Duncan

Re: [R] ifelse statement with two vectors of different length

2013-12-18 Thread arun
Hi, Please show a reproducible example. countrydiff - c(Albania, Algeria, Belarus, Canada, Germany) long_df - data.frame(country_name = c(Algeria, Guyana, Hungary, Algeria, Canada, Iran, Iran, Norway,Uruguay, Zimbabwe) )  ifelse(long_df$country_name %in% countrydiff,1,0) # [1] 1 0 0 1 1 0 0 0 0

[R] ifelse statement with two vectors of different length

2013-12-18 Thread Adel
Dear list-members, I have the following problem: I have a vector (countrydiff) with length 72 and another vector (long_df$country_name) which is about 12000 long. Basically what I want to do is to if the factor level (or string name) in long_df$country_name appears on the countrydiff, then

Re: [R] ifelse statement with two vectors of different length

2013-12-18 Thread Adel
Dear Arun Thanks for your reply, it made me realize that the problem was not in the code but in the levels() of the factors. Some countries had some extra spacing which made the ifelse() function not work. So if I modify your code (added space to countrydiff), it will then look something like

Re: [R] ifelse statement with two vectors of different length

2013-12-18 Thread arun
Hi Adel, If the problem is the spacing, then library(stringr) 1*(long_df$country_name %in% str_trim(countrydiff)) # [1] 1 0 0 1 1 0 0 0 0 0 A.K. Dear Arun Thanks for your reply, it made me realize that the problem was not in the code but in the levels() of the factors. Some countries had

Re: [R] ifelse -does it manage the indexing?

2013-12-03 Thread Hadley Wickham
A better solution to this problem is to use character indexing: x - c(Tuesday, Thursday, Sunday) c(Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6, Sunday = 7)[x] http://adv-r.had.co.nz/Subsetting.html#lookup-tables-character-subsetting Hadley On Mon, Dec 2, 2013

Re: [R] ifelse -does it manage the indexing?

2013-12-03 Thread David Winsemius
On Dec 3, 2013, at 5:37 AM, Hadley Wickham wrote: A better solution to this problem is to use character indexing: x - c(Tuesday, Thursday, Sunday) c(Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6, Sunday = 7)[x]

[R] ifelse -does it manage the indexing?

2013-12-02 Thread Bill
ifelse ((day_of_week == Monday),1, ifelse ((day_of_week == Tuesday),2, ifelse ((day_of_week == Wednesday),3, ifelse ((day_of_week == Thursday),4, ifelse ((day_of_week == Friday),5, ifelse ((day_of_week == Saturday),6,7))) In code like the above, day_of_week is a vector and so

Re: [R] ifelse -does it manage the indexing?

2013-12-02 Thread Duncan Murdoch
On 13-12-02 7:33 PM, Bill wrote: ifelse ((day_of_week == Monday),1, ifelse ((day_of_week == Tuesday),2, ifelse ((day_of_week == Wednesday),3, ifelse ((day_of_week == Thursday),4, ifelse ((day_of_week == Friday),5, ifelse ((day_of_week == Saturday),6,7))) In code like the

Re: [R] ifelse -does it manage the indexing?

2013-12-02 Thread Bill
It seems so inefficient. I mean the whole first vector will be evaluated. Then if the second if is run the whole vector will be evaluated again. Then if the next if is run the whole vector will be evaluted again. And so on. And this could be only to test the first element (if it is false for each

Re: [R] ifelse -does it manage the indexing?

2013-12-02 Thread Duncan Murdoch
On 13-12-02 7:49 PM, Bill wrote: It seems so inefficient. I mean the whole first vector will be evaluated. Then if the second if is run the whole vector will be evaluated again. Then if the next if is run the whole vector will be evaluted again. And so on. And this could be only to test the

Re: [R] ifelse -does it manage the indexing?

2013-12-02 Thread Bill
Hi. Thanks. Which part? I looked at the below but I don't think it clearly addresses the nested ifelse situation. ifelse {base}R DocumentationConditional Element Selection Description ifelse returns a value with the same shape as test which is filled with elements selected from either yes or no

Re: [R] ifelse -does it manage the indexing?

2013-12-02 Thread William Dunlap
-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bill Sent: Monday, December 02, 2013 4:50 PM To: Duncan Murdoch Cc: r-help@r-project.org Subject: Re: [R] ifelse -does it manage the indexing? It seems so inefficient. I mean the whole first vector will be evaluated

Re: [R] ifelse -does it manage the indexing?

2013-12-02 Thread Bill
Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bill Sent: Monday, December 02, 2013 4:50 PM To: Duncan Murdoch Cc: r-help@r-project.org Subject: Re: [R] ifelse -does it manage the indexing

Re: [R] ifelse -does it manage the indexing?

2013-12-02 Thread Bill
Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bill Sent: Monday, December 02, 2013 4:50 PM To: Duncan Murdoch Cc: r-help@r-project.org Subject: Re: [R] ifelse -does it manage the indexing

[R] ifelse, apply, if

2013-11-27 Thread Andrea Lamont
Hello: This seems like an obvious question, but I am having trouble answering it. I am new to R, so I apologize if its too simple to be posting. I have searched for solutions to no avail. I have data that I am trying to set up for further analysis (training data). What I need is 12 groups based

Re: [R] ifelse question (I'm not sure why this is working)...

2013-09-10 Thread David Winsemius
On Sep 10, 2013, at 12:40 PM, Jonathan Greenberg wrote: R-helpers: One of my intrepid students came up with a solution to a problem where they need to write a function that takes a vector x and a scalar d, and return the indices of the vector x where x %% d is equal to 0 (x is evenly

Re: [R] ifelse question (I'm not sure why this is working)...

2013-09-10 Thread Jim Lemon
On 09/11/2013 05:40 AM, Jonathan Greenberg wrote: R-helpers: One of my intrepid students came up with a solution to a problem where they need to write a function that takes a vector x and a scalar d, and return the indices of the vector x where x %% d is equal to 0 (x is evenly divisible by d).

[R] ifelse question (I'm not sure why this is working)...

2013-09-10 Thread Jonathan Greenberg
R-helpers: One of my intrepid students came up with a solution to a problem where they need to write a function that takes a vector x and a scalar d, and return the indices of the vector x where x %% d is equal to 0 (x is evenly divisible by d). I thought I had a good handle on the potential

Re: [R] ifelse question (I'm not sure why this is working)...

2013-09-10 Thread William Dunlap
] On Behalf Of Jonathan Greenberg Sent: Tuesday, September 10, 2013 12:40 PM To: r-help Subject: [R] ifelse question (I'm not sure why this is working)... R-helpers: One of my intrepid students came up with a solution to a problem where they need to write a function that takes a vector x

[R] ifelse() applied on function

2013-08-11 Thread Ron Michael
Hi,   How can I apply ifelse function to chose appropriate function?   My goal is user will chose lapply() function if ChooseFn = T otherwise to chose sfLapply() from snowfall package.   I am basically trying to avoid repeatation to write all internal steps, if user choses lapply or sfLapply.

Re: [R] ifelse() applied on function

2013-08-11 Thread Steve Lianoglou
Hi, On Sun, Aug 11, 2013 at 1:18 PM, Ron Michael ron_michae...@yahoo.com wrote: Hi, How can I apply ifelse function to chose appropriate function? My goal is user will chose lapply() function if ChooseFn = T otherwise to chose sfLapply() from snowfall package. I am basically trying to

Re: [R] ifelse() applied on function

2013-08-11 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ron Michael Sent: Sunday, August 11, 2013 1:18 PM To: r-help@r-project.org Subject: [R] ifelse() applied on function Hi, How can I apply ifelse function to chose appropriate

[R] Ifelse leading to inconsistent result

2013-06-26 Thread Neville O'Reilly
I have used ifelse in count variables to count the number of times in a simulation the values of a vector of logprice fall within mutually exclusive ranges. However, there is a double count in the result i.e. i am getting output indicating values falling in mutually exclusive ranges. Here is

Re: [R] Ifelse leading to inconsistent result

2013-06-26 Thread Duncan Murdoch
On 26/06/2013 11:40 AM, Neville O'Reilly wrote: I have used ifelse in count variables to count the number of times in a simulation the values of a vector of logprice fall within mutually exclusive ranges. However, there is a double count in the result i.e. i am getting output indicating

Re: [R] Ifelse leading to inconsistent result

2013-06-26 Thread peter dalgaard
On Jun 26, 2013, at 17:40 , Neville O'Reilly wrote: I have used ifelse in count variables to count the number of times in a simulation the values of a vector of logprice fall within mutually exclusive ranges. However, there is a double count in the result i.e. i am getting output

Re: [R] Ifelse leading to inconsistent result

2013-06-26 Thread David Carlson
of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Neville O'Reilly Sent: Wednesday, June 26, 2013 10:41 AM To: r-help@r-project.org Subject: [R] Ifelse leading to inconsistent

Re: [R] Ifelse leading to inconsistent result

2013-06-26 Thread Neville O'Reilly
. 848-445-7669 http://fsrm.rutgers.edu/ - Original Message - From: David Carlson dcarl...@tamu.edu To: Neville O'Reilly norei...@stat.rutgers.edu, r-help@r-project.org Sent: Wednesday, June 26, 2013 1:15:06 PM Subject: RE: [R] Ifelse leading to inconsistent result I don't see that you

[R] ifelse to speed up loop?

2013-01-24 Thread Jeffrey Fuerte
Hello, I'm not sure how to explain what I'm looking for but essentially I have a test dataset that looks like this: test: V1 1 1 2 1 3 1 4 2 5 2 6 2 7 1 8 1 9 1 10 2 11 2 12 2 And what I want to be able to do is create another column that captures a grouping variable

Re: [R] ifelse to speed up loop?

2013-01-24 Thread Bert Gunter
Your query is a little unclear to me, but I suspect ?rle is what you want. -- Bert On Thu, Jan 24, 2013 at 1:20 PM, Jeffrey Fuerte fuert...@vcu.edu wrote: Hello, I'm not sure how to explain what I'm looking for but essentially I have a test dataset that looks like this: test: V1 1

Re: [R] ifelse to speed up loop?

2013-01-24 Thread arun
#9   1 3 #10  2 4 #11  2 4 #12  2 4 A.K. - Original Message - From: Jeffrey Fuerte fuert...@vcu.edu To: r-help@r-project.org Cc: Sent: Thursday, January 24, 2013 4:20 PM Subject: [R] ifelse to speed up loop? Hello, I'm not sure how to explain what I'm looking

Re: [R] ifelse to speed up loop?

2013-01-24 Thread Bert Gunter
I should add that if your V1 column is numeric, fiddling around with ?diff or equivalent will also identify the groupings for you and may be faster than rle(). -- Bert On Thu, Jan 24, 2013 at 3:32 PM, Bert Gunter bgun...@gene.com wrote: Your query is a little unclear to me, but I suspect ?rle

Re: [R] ifelse to speed up loop?

2013-01-24 Thread arun
HI, This might be better. test$group-cumsum(abs(c(1,diff(test[,1] A.K. - Original Message - From: Jeffrey Fuerte fuert...@vcu.edu To: r-help@r-project.org Cc: Sent: Thursday, January 24, 2013 4:20 PM Subject: [R] ifelse to speed up loop? Hello, I'm not sure how to explain what

Re: [R] ifelse to speed up loop?

2013-01-24 Thread William Dunlap
] On Behalf Of arun Sent: Thursday, January 24, 2013 3:37 PM To: Jeffrey Fuerte Cc: R help Subject: Re: [R] ifelse to speed up loop? HI, This might be better. test$group-cumsum(abs(c(1,diff(test[,1] A.K. - Original Message - From: Jeffrey Fuerte fuert...@vcu.edu To: r

Re: [R] ifelse to speed up loop?

2013-01-24 Thread William Dunlap
Yes. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Thursday, January 24, 2013 3:53 PM To: William Dunlap Cc: R help Subject: Re: [R] ifelse to speed up loop? Hi, I guess you meant: c(TRUE, cumsum

Re: [R] ifelse to speed up loop?

2013-01-24 Thread arun
fuert...@vcu.edu Cc: R help r-help@r-project.org Sent: Thursday, January 24, 2013 6:48 PM Subject: RE: [R] ifelse to speed up loop? I like   v - test[,1]   c(TRUE, cumsum( v[-length(v)] != v[-1] )) (R's arithmetic on logicals treats TRUE as 1 and FALSE as 0.) Bill Dunlap Spotfire, TIBCO Software

Re: [R] ifelse to speed up loop?

2013-01-24 Thread Jeff
3 # 1 3 #9 1 3 #10 2 4 #11 2 4 #12 2 4 A.K. - Original Message - From: Jeffrey Fuerte fuert...@vcu.edu To: r-help@r-project.org Cc: Sent: Thursday, January 24, 2013 4:20 PM Subject: [R] ifelse to speed up loop? Hello, I'm not sure how

Re: [R] ifelse to speed up loop?

2013-01-24 Thread William Dunlap
-project.org] On Behalf Of Jeff Sent: Thursday, January 24, 2013 4:08 PM To: arun Cc: R help; Jeffrey Fuerte Subject: Re: [R] ifelse to speed up loop? Thank you for the tips. I should mention that the V1 is numeric in this case but I am trying to automate the overall procedure so it may

Re: [R] ifelse to speed up loop?

2013-01-24 Thread arun
Fuerte fuert...@vcu.edu; R help r-help@r-project.org Sent: Thursday, January 24, 2013 7:08 PM Subject: Re: [R] ifelse to speed up loop? Thank you for the tips. I should mention that the V1 is numeric in this case but I am trying to automate the overall procedure so it may not be numeric always

Re: [R] ifelse + numeric

2012-11-22 Thread djbanana
Thanks, it worked without quotation marks. -- View this message in context: http://r.789695.n4.nabble.com/ifelse-numeric-tp4650390p4650482.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list

[R] ifelse + numeric

2012-11-21 Thread djbanana
Hi, I have a data frame and I need to add another column. I am using: data[,4] - ifelse(data[,3]1,data[,1]/(1-data[,3]),NA) This is returning values but are in quotation marks. The error I am getting is non-numeric argument to binary operator I need column four in data to be numeric. Tried

Re: [R] ifelse + numeric

2012-11-21 Thread jim holtman
Try leaving the quote marks off the NA: data[,4] - ifelse(data[,3]1,data[,1]/(1-data[,3]),NA) You are putting a character value with the NA which converts everything else to a character. If you had examined the dataframe with 'str(data)' you would probably have seen the problem. On Wed, Nov

Re: [R] ifelse reformulation

2012-10-25 Thread arun
-project.org Cc: Sent: Thursday, October 25, 2012 12:55 PM Subject: Re: [R] ifelse reformulation Arun, thank you very much... but a new problem arose... What if... in the variable group that i want to compare, there is numeric and non numeric types? Or, if you think its better, can i have two

Re: [R] ifelse reformulation

2012-10-24 Thread arun
(test1,1,function(x) ifelse(any(x[4:6]==40|x[4:6]==50|x[4:6]==60|x[4:6]==70),0,1)))  #[1] 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 A.K. From: Bruno Marques brunos...@gmail.com To: arun smartpink...@yahoo.com Sent: Wednesday, October 24, 2012 12:47 PM Subject: Re: [R] ifelse

[R] ifelse reformulation

2012-10-12 Thread brunosm
Hi, i'm trying to simplify some R code but i got stucked in this: test-data.frame(cbind(id,x1,x2,x3,x4,x5,x6,x7)) test test id x1 x2 x3 x4 x5 x6 x7 1 1 36 26 21 32 31 27 31 2 2 45 21 46 50 22 36 29 3 3 49 47 35 44 33 31 46 4 4 42 32 38 28 39 45 32 5 5 29 42 39 48 25 35 34 6 6 39

Re: [R] ifelse reformulation

2012-10-12 Thread brunosm
That was exacly what i was looking for! Thanks a lot! Cheers! -- View this message in context: http://r.789695.n4.nabble.com/ifelse-reformulation-tp4645981p4645990.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org

Re: [R] ifelse reformulation

2012-10-12 Thread arun
To: r-help@r-project.org Cc: Sent: Friday, October 12, 2012 10:18 AM Subject: Re: [R] ifelse reformulation That was exacly what i was looking for! Thanks a lot! Cheers! -- View this message in context: http://r.789695.n4.nabble.com/ifelse-reformulation-tp4645981p4645990.html Sent from the R

Re: [R] ifelse reformulation

2012-10-12 Thread brunosm
Hi arun kirshna just let me ask you something else. Imagin that i only want to search in the variables x3,x4 and x5. How can i do this? Regards, Bruno -- View this message in context: http://r.789695.n4.nabble.com/ifelse-reformulation-tp4645981p4646013.html Sent from the R help mailing

Re: [R] ifelse reformulation

2012-10-12 Thread Pieter Schoonees
11:51 To: r-help@r-project.org Subject: [R] ifelse reformulation Hi, i'm trying to simplify some R code but i got stucked in this: test-data.frame(cbind(id,x1,x2,x3,x4,x5,x6,x7)) test test id x1 x2 x3 x4 x5 x6 x7 1 1 36 26 21 32 31 27 31 2 2 45 21 46 50 22 36 29 3 3 49 47

[R] Ifelse Execution

2012-10-01 Thread Bhupendrasinh Thakre
Hi Everyone, I am trying to run a time based query and need some of your help. Not much of data or packages. Just a simple one. Query I am trying to execute. ifelse ((as.numeric(as.POSIXct(2012-10-01 20:38:00))), (rnorm(1,2,1)),(Sys.sleep())) Note. Why I am using as.numeric is as I have a

Re: [R] Ifelse Execution

2012-10-01 Thread Jeff Newmiller
Ifelse is a vector function and is absolutely inappropriate for that use. Use if instead. Also, read the help for Sys.sleep... you need to tell it how long you want to sleep. You should compute how long that is from now and sleep that long.

[R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hi R-Helpers, I don't think I need to post a dataset for this question but if I do, I can. Anyway, I am having a lot of trouble with the ifelse command. Here is my code: vn$PM.DIST_flag - ifelse( (vn$PM.EXP 0.0) (vn$PM.DIST.TOT != 1.0), 1, 0 ) And here is my output that doesn't make ANY

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread R. Michael Weylandt
On Fri, Aug 24, 2012 at 3:22 PM, Jennifer Sabatier plessthanpointohf...@gmail.com wrote: Hi R-Helpers, I don't think I need to post a dataset for this question but if I do, I can. Anyway, I am having a lot of trouble with the ifelse command. You probably should have: dput() makes it super

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Oops, sorry, I thought I was in plain text. I can't tell the difference because I use so little formatting in my emails. Try this (a truncated version since I have to hand space everything): PM.EXP PM.DIST.TOT PM.DIST_flag 0 00 6417 1

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Bert Gunter
... and if Michael is correct, there is a lesson here: Think of how much time and aggravation you would have saved yourself if you had FIRST made an effort to read the docs. The FAQ's are there for a reason. As is An Introduction to R, which also should be read before posting on this list. If

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Peter Ehlers
On 2012-08-24 13:22, Jennifer Sabatier wrote: Hi R-Helpers, I don't think I need to post a dataset for this question but if I do, I can. Anyway, I am having a lot of trouble with the ifelse command. Here is my code: vn$PM.DIST_flag - ifelse( (vn$PM.EXP 0.0) (vn$PM.DIST.TOT != 1.0), 1, 0 )

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Bert, I will thank you not to condescend to me, as I am too damn old (40) to be treated that way. You didn't even offer a solution to my problem. You only came to chastise me with regards to your assumptions about me, which is very annoying. While I am at the beginner level of R, I am not an

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hi Peter, I'm really sorry, I thought I was in plain text. I don't use any formatting in my emails and in Gmail the HTML looks the same as plain text. Anyway, I've attached the data (I didn't think we could do that but I am frequently wrong). I say many cases because this is just a subset of

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Rui Barradas
Hello, Michael's standard guess, FAQ 7.31, was also mine, but is wrong. The error is in Jennifer's flag column, not the result of her ifelse. (!) x - scan(what=character, text= PM.EXP PM.DIST.TOT PM.DIST_flag 0 0 0 0 0 0 0 0 0 177502 1 0 31403 1 0 0 0 0 1100549 1 0 38762 1 0 0 0 0

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
BTW - no one else who has replied to this topic was snobby or unfriendly and I thank you very much for trying to help me. It's just Bert is not the first to respond to my request for help as such. As someone looking forward to becoming an advanced R programmer in my statistical work it is

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hi Rui, Thanks so much for responding but I think with my HTML problem the vn data you made must not be the same. I tried running your code on the data (I uploaded a copy) and I got the same thing I had before. Jen On Fri, Aug 24, 2012 at 5:28 PM, Rui Barradas ruipbarra...@sapo.pt wrote:

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread R. Michael Weylandt
Off the wall / wild guess, do you use attach() frequently? Not entirely sure how it would come up, but it tends to make weird errors like this occur. M On Fri, Aug 24, 2012 at 4:36 PM, Jennifer Sabatier plessthanpointohf...@gmail.com wrote: Hi Rui, Thanks so much for responding but I think

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hi Michael, No, I never use attach(), exactly for the reasons you state. To do due diligence I did a search of code for the function and it didn't come up (I would have been shocked because I never us it!). Now that real data is up, does your suggestion still apply? I am reading it now.

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Rui Barradas
No data arrived to me. Rui Barradas Em 24-08-2012 22:46, Jennifer Sabatier escreveu: Hi Michael, No, I never use attach(), exactly for the reasons you state. To do due diligence I did a search of code for the function and it didn't come up (I would have been shocked because I never us it!).

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread R. Michael Weylandt
On Fri, Aug 24, 2012 at 4:46 PM, Jennifer Sabatier plessthanpointohf...@gmail.com wrote: Hi Michael, No, I never use attach(), exactly for the reasons you state. To do due diligence I did a search of code for the function and it didn't come up (I would have been shocked because I never us

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread R. Michael Weylandt
On Fri, Aug 24, 2012 at 4:50 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: On Fri, Aug 24, 2012 at 4:46 PM, Jennifer Sabatier plessthanpointohf...@gmail.com wrote: Hi Michael, No, I never use attach(), exactly for the reasons you state. To do due diligence I did a search of code

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Oh, sorry, I first though you couldn't post data to the list, but then I thought I remembered other people doing so, so I tried to post it. Here is a copy. Thanks, Jen On Fri, Aug 24, 2012 at 5:49 PM, Rui Barradas ruipbarra...@sapo.pt wrote: No data arrived to me. Rui Barradas Em

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hi Michael, Thanks for letting me know how to post data. I will try to upload it that way in a second. I can usually use code to make a reproducible dataset but this time with the ifelse behaving strangely (perhaps, it's probably me) I didn't think I could do it easily so I figured I would just

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Peter Ehlers
I see that you got other responses while I was composing an answer. Your 'example.csv' did come through for me, but I still can't replicate your PM.DIST_flag variable. Specifically, observations 30, 33, 36 and 40 are wrong. I agree with Rui, that there's something else going on. The data you've

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
AHHH I GOT IT!! And I *think* I understand about floating point arithmetic.. In this case vn$PM.DIST.TOT is the sum of proportions. So, it should be anywhere 0 and 1. In our case, if it's anything other than 1 when vn$PM.EXP is greater than 0 then it means something is wrong

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread R. Michael Weylandt
On Fri, Aug 24, 2012 at 7:29 PM, Jennifer Sabatier plessthanpointohf...@gmail.com wrote: AHHH I GOT IT!! And I *think* I understand about floating point arithmetic.. Well then you're doing much better than the rest of us: it's quite a difficult subject and only gets trickier as

Re: [R] ifelse problem - bug or operator error

2012-08-24 Thread Jennifer Sabatier
Hah - I guess I didn't mean I understood it in full as I expect I will run into it again without anticipating it. But, now that I know the old adage I will look there first when I run into a problem. Also, I used the square root of machine precision instead - thanks for that, too. Thank you,

[R] ifelse help

2012-07-10 Thread Jeff
I'm sure this is easy, but I'm new to R and can't find any example of the following. Here's what I'm trying to do in pseudo-code. data$newvar - ifelse(data$oldvar1 == 8, 1,data$oldvar2) In other words, if the existing variable equals 8, then the new variable should equal 1, otherwise the

Re: [R] ifelse help

2012-07-10 Thread jim holtman
Seems to work for me: x - data.frame(old1 = sample(c(1,2,8), 10, TRUE), old2 = 1:10) x$new - ifelse(x$old1 == 8, 1, x$old2) x old1 old2 new 1 11 1 2 22 2 3 23 3 4 84 1 5 15 5 6 86 1 7 87 1 8 28 8 9 29

Re: [R] ifelse help

2012-07-10 Thread Nordlund, Dan (DSHS/RDA)
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jeff Sent: Tuesday, July 10, 2012 5:26 PM To: r-help Subject: [R] ifelse help I'm sure this is easy, but I'm new to R and can't find any example of the following. Here's

Re: [R] ifelse help

2012-07-10 Thread Jeff
At 07:41 PM 7/10/2012, you wrote: Seems to work for me: x - data.frame(old1 = sample(c(1,2,8), 10, TRUE), old2 = 1:10) x$new - ifelse(x$old1 == 8, 1, x$old2) x Thanks Jim and Dan. The problem ended up with a missing values issue that threw me off. When your post confirmed that my code

Re: [R] ifelse help

2012-07-10 Thread Jeff Newmiller
You failed to tell us any of: the actual code you used, the data you were working with, or the actual error you got. Your pseudo-code looks okay to me, so I suggest you read the Posting Guide and try again. (Anything other than a complete reproducible example of your problem is unlikely to

Re: [R] Ifelse on matrix using a vector argument

2012-06-06 Thread Özgür Asar
A generalized procedure for real life datasets might be out-rep(matrix(arg),ncol(ma))-ma out[which(arg==0),]--out[which(arg==0),] out Ozgur -- View this message in context: http://r.789695.n4.nabble.com/Ifelse-on-matrix-using-a-vector-argument-tp4632485p4632490.html Sent from the R help

Re: [R] Ifelse on matrix using a vector argument

2012-06-05 Thread Özgür Asar
Hi, A practical way migh be out-rep(matrix(arg),4)-ma out[2,]--out[2,];out[5,]--out[5,] out [,1] [,2] [,3] [,4] [1,] 0.8 0.4 0.80 1.0 [2,] 1.0 0.0 1.00 0.3 [3,] 0.7 0.9 0.65 1.0 [4,] 1.0 0.5 0.60 0.9 [5,] 0.5 1.0 0.00 1.0 Best Ozgur -- View this message in context:

  1   2   3   >