[R] Automatically assign symbol for statistical significance to x given value of x

Tormod Bøe tormod.rhjelp at gmail.com
Mon Jul 20 17:36:21 CEST 2009


Dear r-help users,

I am using Sweave and Latex to create tables with output from several
statistical test. As an example: I have a grouping variable "group"
with two levels ("x" and "y") which I compare on variables ("a" and
"b").

I have created a table in which means, standard deviations, and the
statistic and p.value resulting from a t.test is printed. The table
looks something like:

 group(x)                  group(y)
mean        sd        mean      sd     t-value p-value  sig.
mean(x,a)  sd(x,a) mean(y,a) sd(y,a)    t.a      p.a
mean(x,b)  sd(x,b) mean(y,b) sd(y,b)    t.b      p.b

What I would like to be able to add to this table is an indication by
means of asterisks ("*") the level of significance of the p.value(s).

I am after an expression to put in column "sig." which evaluates the
p.value and prints *, ** or *** depending on it's value (e.g. if it is
less than .05 print "*", but if it is less than .01 print "**", but if
it is less than .001 print "***", else print " ").

I am able to use a simple function like if (p.value<0.5) print("*")
else print(" "),
but I have not been able to work out how to nest the "if" expressions correctly.

Any help would be greatly appreciated.

Best regards,
Tormod Bøe




More information about the R-help mailing list