Re: [R] How to find the min and max of two variables in a data frame

2009-07-24 Thread Bill.Venables
o: r-help@r-project.org Subject: [R] How to find the min and max of two variables in a data frame I have two variables in a data frame, I want to generate two additional variables. For every observations (i.e. every row), I want the first new variable 'min' to carry the minimum of the two

Re: [R] How to find the min and max of two variables in a data frame

2009-07-23 Thread Dimitris Rizopoulos
try this: set.seed(123) dat <- data.frame(x = round(rnorm(10)), y = round(rnorm(10))) dat$Min <- pmin(dat$x, dat$y) dat$Max <- pmax(dat$x, dat$y) dat ind <- dat$Min != dat$Max dat[ind, ] I hope it helps. Best, Dimitris kxk wrote: I have two variables in a data frame, I want to generate tw

[R] How to find the min and max of two variables in a data frame

2009-07-23 Thread kxk
I have two variables in a data frame, I want to generate two additional variables. For every observations (i.e. every row), I want the first new variable 'min' to carry the minimum of the two existing variables, and I want the second new variable 'max' to carry the maximum of the two existing vari