[R] using pmax in presence of NAs
Dimitri Liakhovitski
dimitri.liakhovitski at gmail.com
Wed Nov 16 21:58:34 CET 2016
Hello!
I need to calculate the maximum of each row of a data frame.
This works:
x <- data.frame(a = 1:5, b=11:15, c=111:115)
x
do.call(pmax, x)
[1] 111 112 113 114 115
However, how should I modify it if my data frame has NAs?
I'd like it to ignore NAs and return the maximum of all non-NAs in each row:
x <- data.frame(a = c(1:5), b=11:15, c=c(111:114,NA))
x
I'd like it to return:
[1] 111 112 113 114 15
Thanks a lot!
--
Dimitri Liakhovitski
More information about the R-help
mailing list