Re: [R] using pmax in presence of NAs

2016-11-16 Thread Dimitri Liakhovitski
Thank you, Peter! On Wed, Nov 16, 2016 at 4:21 PM, peter dalgaard wrote: > >> On 16 Nov 2016, at 21:58 , Dimitri Liakhovitski >> wrote: >> >> Hello! >> >> I need to calculate the maximum of each row of a data frame. >> This works: >> >> x <-

Re: [R] using pmax in presence of NAs

2016-11-16 Thread peter dalgaard
> On 16 Nov 2016, at 21:58 , Dimitri Liakhovitski > wrote: > > 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 > >

Re: [R] using pmax in presence of NAs

2016-11-16 Thread Dimitri Liakhovitski
Thanks a lot, Sarah. I just had no idea where to put na.rm = T in the do.call call. Appreciate it! Dimitri On Wed, Nov 16, 2016 at 4:06 PM, Sarah Goslee wrote: > pmax has a na.rm argument. Why not just use that? > > x <- data.frame(a = c(1:5), b=11:15, c=c(111:114,NA)) >

Re: [R] using pmax in presence of NAs

2016-11-16 Thread Sarah Goslee
pmax has a na.rm argument. Why not just use that? x <- data.frame(a = c(1:5), b=11:15, c=c(111:114,NA)) > do.call(pmax, c(x, na.rm=TRUE)) [1] 111 112 113 114 15 On Wed, Nov 16, 2016 at 3:58 PM, Dimitri Liakhovitski wrote: > Hello! > > I need to calculate the

Re: [R] using pmax in presence of NAs

2016-11-16 Thread Dimitri Liakhovitski
To clarify: I know I could do: apply(x, 1, max, na.rm = T) But I was wondering if one can modify the pmax one... On Wed, Nov 16, 2016 at 3:58 PM, Dimitri Liakhovitski wrote: > Hello! > > I need to calculate the maximum of each row of a data frame. > This works: >

[R] using pmax in presence of NAs

2016-11-16 Thread Dimitri Liakhovitski
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