Skip to content

Seeking feedback on my first attempt at R programming

4 messages · Paul Miller, Gabor Grothendieck

#
On Wed, Dec 22, 2010 at 4:26 PM, Paul Miller <pjmiller_57 at yahoo.com> wrote:
1.  Better to stay away from within unless you really need it.   Use
with or transform:

fev <- transform(fev,
  trtgrp = factor(trtgrp, labels = c("ABC-123","Placebo")),
  chg = fev6 - fev0
)

2. mean and sd act column-wise but t.test does not.   A minimal change
to make it work would be to add an apply to the t.value and p.value:

summaryfn2a <- function(x)
   data.frame(n=sum(complete.cases(x)),mean=mean(x),std.dev=sd(x),
    t.value=apply(x, 2, function(x) (t.test)(x)$statistic),
    p.value=apply(x, 2, function(x) (t.test)(x)$p.value))
cfev <- na.omit(fev)
by(cfev[3:5],cfev[2],summaryfn2a)
1 day later