Re: [R] if statement problem

2011-12-25 Thread Rui Barradas
Hello again. I don't understand what didn't work. First, it seems better to use 'nrow', the result is the same stopifnot(length(x[,1]) == nrow(x)) Then your multiple OR condition. #if((x[i,1] || x[i,2] || x[i,3] || x[i,4]) < 5) x <- matrix(1:24, ncol=4) for(i in 1:nrow(x)) if(any(x

Re: [R] if statement problem

2011-12-25 Thread Uwe Ligges
On 24.12.2011 12:03, reena wrote: It didn't work. :( What did not work??? Please do not misuse the R-help mailing list! Its posting guide clearly asks you to cite the thread and specify reproducible examples that make other able to help. Best, Uwe Ligges -- View this message in cont

Re: [R] if statement problem

2011-12-24 Thread reena
It didn't work. :( -- View this message in context: http://r.789695.n4.nabble.com/if-statement-problem-tp4230026p4230933.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/lis

Re: [R] if statement problem

2011-12-24 Thread Patrick Burns
This is almost Circle 8.1.7 of 'The R Inferno': http://www.burns-stat.com/pages/Tutor/R_inferno.pdf but is making the mistake in the other direction. On 23/12/2011 22:40, reena wrote: Hello, I want to do fisher test for the rows in data file which has value less than 5 otherwise chi square te

Re: [R] if statement problem

2011-12-23 Thread Rui Barradas
reena wrote > > Hello, > > I want to do fisher test for the rows in data file which has value less > than 5 otherwise chi square test .The p values from both test should be > stored in one resulted file. but there is some problem with bold if > statement. I don't know how > implement this line

Re: [R] if statement problem

2008-01-01 Thread Gabor Grothendieck
Try: das$danger <- with(das, (age > 65) * (bmi > 30)) On Jan 1, 2008 5:03 PM, Gerard Smits <[EMAIL PROTECTED]> wrote: > Hi All, > > I have a small dataset named das (43 cases) in which I am trying to > create a binary outcome (1/0) based on the following code: > > if (das$age>65 && das$bmi>30) {

Re: [R] if statement problem

2008-01-01 Thread Gerard Smits
Hi Domenico, I was incorrectly assuming it would use a vector of equal length to my data. frame. Thanks for the clarification. Also, thanks for the many alternate programming approaches provided by others. Gerard At 02:25 PM 1/1/2008, Domenico Vistocco wrote: >You should look for your answer

Re: [R] if statement problem

2008-01-01 Thread Tim Calkins
you could try the following: >das$danger <- 0 >das$danger[das$bmi > 30 & das$age > 65] <- 1 On Jan 2, 2008 9:16 AM, Gerard Smits <[EMAIL PROTECTED]> wrote: > > Thanks, but I tried the single ampersand, but got a warning msg with > the same lack of correct assignment: > > > if (das$age>65 & das

Re: [R] if statement problem

2008-01-01 Thread Domenico Vistocco
You should look for your answer using the help for the if statement (?"if"). The cond argument should be a scalar (otherwise only the first element is used). ?"if" . cond: A length-one logical vector that is not 'NA'. Conditions of length greater than one are accepted with a warnin

Re: [R] if statement problem

2008-01-01 Thread Gerard Smits
Thanks, but I tried the single ampersand, but got a warning msg with the same lack of correct assignment: > if (das$age>65 & das$bmi>30) {das$danger<-1} else das$danger<-0 Warning message: In if (das$age > 65 & das$bmi > 30) { : the condition has length > 1 and only the first element will be

Re: [R] if statement problem

2008-01-01 Thread Christos Hatzis
You need to use '&' instead of '&&': A shorter version of your code using ifelse: das$danger <- with(das, ifelse(age>65 & bmi>30, 1, 0)) HTH -Christos > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Gerard Smits > Sent: Tuesday, January 01, 200