search for: else's

Displaying 20 results from an estimated 78460 matches for "else's".

2005 Nov 10
2
IF/Else
Hi, I am trying to write a for loop with if else statements to calculate biomass density estimates for different types of sampling gear. My code is: bmd=for (i in 1:length(Gear)){ if (Gear==20) {bioden=Biomass/141} else {if (Gear==23) {bioden=Biomass/68}} else {if (Gear==160) {bioden=Biomass/4120}} else {if (Gear==170) {bioden=Biomass/2210}} e...
2011 Nov 15
3
if/else scope
What is wrong with the following? x <- 1:2 if(x[1] > 0) { if(x[2] > 0) { print("1 & 2 > 0") } else { print("1 > 0") } } else { if(x[2] > 0) { print("2 > 0") } else {...
2008 Jun 05
5
vector comparison
...is fairly basic, but I must have somehow missed it in the manuals. I have two vectors, often of unequal length. I would like to compare them for identity. Order of elements do not matter, but they should contain the same. I.e: I want this kind of comparison: > if (1==1) show("yes") else show("blah") [1] "yes" > if (1==2) show("yes") else show("blah") [1] "blah" > Only replace the numbers with for instance the vectors > a = c("a") > b = c("b","c") > c = c("c","b")...
2010 Feb 22
3
gsub patterns from vector elements w/out loop?
Dear list, I have two vectors: x <- c("one","two") y <- paste(rep(x,2),"blah") I want to replace all occurrences of each element of x in y with something else, so that y looks like this: y [1] "something else blah" "something else blah" "something else blah" [4] "something else blah" I can do this using a loop: for ( i in 1:length(x) ) { y <- gsub(x[i],"something else",y) } Surely, there must be...
2010 Feb 15
1
argh .. if/else .. why?
Hello, would someone please help explain the following inconsistency in the if/else statement to me? The format of the if/else #3 below is ok, but if/else #1 is not? (I get an "unexpected else" type error.) In order for it to work I have to use if/else #2 Thanks .. maybe there is some reason for this, but this looks very inconsistent to me. R version 2.10.1 (2009-12-1...
2012 Jan 22
2
if/else statement without curly brackets gives a problem
Hello, This example seems strange to me: > if (2 > 3) print('Yes'); else print('No') Error: unexpected 'else' in " else" > {if (2 > 3) print('Yes'); else print('No')} Error: unexpected 'else' in "{if (2 > 3) print('Yes'); else" > { + if (2 > 3) print('no') + else print('ye...
2010 Sep 14
4
If then else with command for
...34,231,782,184,182,432,49,63,94,124,69,53,91,451,53,21,42,50,40,32,58,26,28,61,60,35,764,105,592,55,28,46,34,123,41,54,207,64,562,295,226,63,233) R<-142 color<-rep(0,142) for(i in 1:R){ x<-sample(x,142,replace=FALSE) if (!3471 %in% x & !6263 %in% x & !6720 %in% x){color[i]<-1} else if (3471 %in% x & !6263 %in% x & !6720 %in% x){color[i]<-2} else if (!3471 %in% x & 6263 %in% x & !6720 %in% x){color[i]<-3} else if (!3471 %in% x & !6263 %in% x & 6720 %in% x){color[i]<-4} else if (3471 %in% x & 6263 %in% x & !6720 %in% x){color[i]<-...
2009 Nov 13
4
Simple if else statement problem
Hello, I am getting an error with the following code: if( P2 > P1) + { + P<-P2 + } > else Erro: unexpected 'else' in "else" > { + P<-P1 + } I checked the syntax so I don?t understand, I have other if else statements with the same syntax working. Thanks in advance -- View this message in context: http://old.nabble.com/Simple-if-else-statement-problem-tp26340336p...
2007 May 16
2
use mathematics formula
...'s a lil hard the data frame that I'm working on is as follow > donCalcara2 Id_Cara Form_C 1 743 if C325=. then C743=(C152/C103)*100| else C743=(C152/C325)*100 2 627 if C137=. Then C627=.| else do| if C109=. Then C627=(C138/S138)*(100-C137)| else C627=(C138/S138)*C109| end 3 638 C638 = C103 / S103 4 740...
2007 Mar 06
2
parse error with if else (PR#9551)
Full_Name: Stephanie MAHEVAS Version: 2.4.1 OS: Windows NT Submission from: (NULL) (134.246.55.50) the two following instructions provide a synthax error : if ( 5 > 4 ) cat("ok1") else cat("ok2") and if ( 5 > 4 ){ cat("ok1")} else cat("ok2") whereas these ones don't if ( 5 > 4 ) cat("ok1") else cat("ok2") and if ( 5 > 4 ){ cat("ok1") }else cat("ok2") It looks like a parser problem. If else i...
2009 Mar 09
0
Crash when reloading AEL
...texts with a bunch of ifTime()-statements. If I delete or make the following contexts empty "ael reload" works just like it should. context contexta { _X. => { NoOp(Check where to send the call); ifTime(0:00-4:59|mon-fri|*|*) { Playback(prompts/SwitchClosedRT_); } else ifTime(5:00-6:29|mon-fri|*|*) { jump ${EXTEN}@context1; } else ifTime(6:30-18:59|mon-thu|*|*) { jump ${EXTEN}@context2; } else ifTime(6:30-21:59|fri|*|*) { jump ${EXTEN}@context2; } else ifTime(19:00-23:59|mon-thu|*|*) { jump ${EXTEN}@context1; } else ifTime(...
2007 Jun 20
4
Got "Unexpected ELSE error"
Dear R-users, I have a problem with the IF-ELSE syntax. Please look at the folllowing code and tell me what's wrong: a <- TRUE if ( a ) { cat("TRUE","\n") } else { cat("FALSE","\n") } If I try to execute with R I get: Error: syntax error, unexpected ELSE in "else" Th...
2003 Feb 11
4
How "else" works
I have what is likely to be a simple question about the else keyword. The usage in the help pages is as follows: if(cond) cons.expr else alt.expr I would expect to be able to use it in the following way as well: if(cond){ cons.expr } else alt.expr This results a syntax error. Am I doing something wrong, or doesn't R support the spanning of...
2005 Sep 13
11
if() command
Hi everyone ! Could you please help me with this problem ? I??ve trying to write a code that assign to a variable the content from another, but all I??ve got is a message error. For example: if (age <=10) {group == 1} else if (age > 10 & age <= 20) {group == 2} else {group == 3} Syntax error Or if (age <=10) {group == 1} else (age > 10 & age <= 20) {group == 2} else {group == 3} Syntax error I know that is possible to find the solution by ifelse command or even recode command, but I??d li...
2011 Jul 25
1
Problem with random number simulation
...if (x[count] > 0.15 & x[count]< 0.65) { if(x[count]>y[count]) { xval[count]=2 yval[count]=0 } else { yval[count]=2 xval[count]=0 } } else if (x[count]<=0.15) { if(y[count]&lt;a)...
2009 Feb 24
1
R parser for If-else
Hi list, I don't know if somebody has spent a lot of time debugging strange problems with if else positioning - the parser seems to recognize only the syntax bellow - this is the only way of making these pieces of code to work. As far as i'm concerned, no examples were available (it would be so awesome to have them in the introductory manual!) #Try to change the placement of the keywords...
2011 Jan 26
2
applying a set of rules to each row
...The retirement plan indicates what system the employee is enrolled under. The data does contain a few other retirement plans, for now I want to just ignore those plans. I have labeled plans as 1-CSRS and 2-FERS, and 3-Other. My first attempt at applying the rules was through a complex nesting of ifelse statements, this was not very successful and quite difficult to follow. I then wrote a function and tried using "apply" unsuccessfully. The function is shown below. I would like to put a short script or function together that would allow for an efficient application of the rules to each...
2009 Oct 03
3
else if statement error
Hello, I am doing a simple if else statement in R. But it always comes out error such as 'unexpected error' There are two variables. ini and b. when ini=1, a=3; when ini>1 and b>2, a=5; all other situations, a=6. I don't know where it is wrong. Here is my code ini=3 b=4 if (ini==1) { a=3 } else if...
2003 Nov 13
4
Problem with parser and if/else
Dear r-help people, could you confirm that this is correct behaviour for R? I am using RH9. the code: x1 <- 1:6 t1 <- 5 if (length(x1) >= t1) { cat("in the if \n") } else { cat("in the else\n") } runs fine: > source("test_if_else.R") in the if > but the code: x1 <- 1:6 t1 <- 5 if (length(x1) >= t1) { cat("in the if 2\n") } else { cat("in the else\n") } fails with the error: > source("test_if_else2...
2007 May 02
2
I need help
hello, I need help because I don't understand the syntaxe "else" how can I write it for example I writed a script to cut missings values and I have errors > if(na==length(C)){ + pos=match(0,match(donGeno[[na-1]],donGeno[[na]],nomatch=0)) + for(k in 1:(na-1)) { + if(pos==1) {donGe...