Re: [R] How to pass na.rm=T to a user defined function

2016-07-29 Thread Jun Shen
Thanks David.This is working perfectly! On Fri, Jul 29, 2016 at 9:00 PM, David Winsemius wrote: > > > On Jul 29, 2016, at 5:52 PM, David Winsemius > wrote: > > > > > >> On Jul 29, 2016, at 5:08 PM, Jun Shen wrote: > >> > >> Thanks Jeff/David for the reply. I wasn't clear in the previous > mess

Re: [R] How to pass na.rm=T to a user defined function

2016-07-29 Thread David Winsemius
> On Jul 29, 2016, at 5:52 PM, David Winsemius wrote: > > >> On Jul 29, 2016, at 5:08 PM, Jun Shen wrote: >> >> Thanks Jeff/David for the reply. I wasn't clear in the previous message. the >> problem of using na.omit is it will omit the whole row where there is at >> least one NA, even when

Re: [R] How to pass na.rm=T to a user defined function

2016-07-29 Thread David Winsemius
> On Jul 29, 2016, at 5:08 PM, Jun Shen wrote: > > Thanks Jeff/David for the reply. I wasn't clear in the previous message. the > problem of using na.omit is it will omit the whole row where there is at > least one NA, even when some variables do have non-NA values. Did you actually run the

Re: [R] How to pass na.rm=T to a user defined function

2016-07-29 Thread Jun Shen
Thanks Jeff/David for the reply. I wasn't clear in the previous message. the problem of using na.omit is it will omit the whole row where there is at least one NA, even when some variables do have non-NA values. For example: let's define a new function N <- function(x) length(x[!is.na(x)]) test <

Re: [R] How to pass na.rm=T to a user defined function

2016-07-28 Thread David Winsemius
> On Jul 28, 2016, at 7:37 PM, Jun Shen wrote: > > Because in reality the NA may appear in one variable but not others. For > example for ID=1, CL may be NA but not for others, For ID=2, V1 may be NA > etc. To keep all the IDs and all the variables in one data frame, it's > inevitable to see som

Re: [R] How to pass na.rm=T to a user defined function

2016-07-28 Thread Jun Shen
Because in reality the NA may appear in one variable but not others. For example for ID=1, CL may be NA but not for others, For ID=2, V1 may be NA etc. To keep all the IDs and all the variables in one data frame, it's inevitable to see some NA On Thu, Jul 28, 2016 at 10:22 PM, Jeff Newmiller wrot

Re: [R] How to pass na.rm=T to a user defined function

2016-07-28 Thread Jeff Newmiller
Why not remove it yourself before passing it to those functions? -- Sent from my phone. Please excuse my brevity. On July 28, 2016 5:51:47 PM PDT, Jun Shen wrote: >Dear list, > >I write a small function to calculate multiple stats on multiple >variables >and export in a format exactly the way I

[R] How to pass na.rm=T to a user defined function

2016-07-28 Thread Jun Shen
Dear list, I write a small function to calculate multiple stats on multiple variables and export in a format exactly the way I want. Everything seems fine until NA appears in the data. Here is my function: do.stats <- function(data, stats.func, summary.var) as.data.frame(signif(sappl