Thanks David and Patrick,

I need to use two statements for the if condition specified. Since the first statement feeds into the second, the ifelse function may just work for the dataset. I'm not sure if there will be issues later but I've tested it and it works.

x <- as.matrix(read.table("test.txt"))

Original code;

if (x < 20){
y <- x + 100 # statement 1a
... # statement 1b
} else {
y <- x -100 # statement 2a
... # statement 2b
}

New code:

n0 <- x + 100
n1 <- n0 + 0

m0 <- x - 100
m1 <- m0 - 0

ifelse(x < 20, n1, m1)


Muhammad

Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling                
                        
Climate Research Laboratory, School of Geography & the Environment  
Oxford University Centre for the Environment
South Parks Road, Oxford, OX1 3QY, United Kingdom Tel: +44 (0)1865-285194 Mobile: +44 (0)7854-625974
Email: muhammad.ra...@ouce.ox.ac.uk

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to