[R] Conditional Execution Error

Steve Murray smurray444 at hotmail.com
Thu Aug 11 22:24:38 CEST 2016


Dear all,


Please could someone explain why 'Version 1' of the code below works, but 'Version 2' produces an error (albeit following the correct output)?


#Version 1

h <- 10
j <- -5

if(h < j) {
print("statement is true")
} else {
while (h >= j) {
print(h)
h <- h - 1
}
}


#Version 2

h <- 10
j <- -5

ifelse(h < j, "statement is true", while(h >= j) {
print(h)
h <- h - 1
}
)



If anyone has an explanation and solution (for avoiding the error), then I'd be pleased to hear it.


Many thanks,

Steve


	[[alternative HTML version deleted]]



More information about the R-help mailing list